Boolean logic & truth tables
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Boolean values
- A Boolean value is either
TrueorFalse. - A condition such as
age >= 18produces a Boolean. - Computers build everything from these two values.
日本語
ブール値
- ブール値は
TrueまたはFalseのどちらかである。 age >= 18などの条件式はブール値を生成する。- コンピュータはこれらの2つの値からすべてを構築する。
English
AND, OR, NOT
andis True only when both sides are True.oris True when at least one side is True.notflips True to False, and False to True.
日本語
AND, OR, NOT
andは両方がTrueの場合にのみTrueとなる。orは少なくとも片方がTrueの場合にTrueとなる。notはTrueをFalseに、FalseをTrueに反転させる。
print(True and False) # False
print(True or False) # True
print(not True) # False
English
A truth table
- A truth table lists every possible input and its output.
- Two inputs (A, B) give four rows: 00, 01, 10, 11.
日本語
真値表
- 真値表は、あり得るすべての入力とその出力をリストする。
- 2つの入力(A, B)则有4つの行: 00, 01, 10, 11。
Explore · 探索
Truth table — try every input
and is true only when both are true; or when at least one is.
English
Build a truth table with loops
- A nested loop over
False, Truewalks through all the combinations.
日本語
ループを使って真値表を作る
False, Trueに対するネストループは、すべての組み合わせを網羅する。
for a in [False, True]:
for b in [False, True]:
print(a, b, a and b)
English
More gates: NAND, NOR, XOR
- NAND is
not (a and b); NOR isnot (a or b). - XOR is True when the inputs are different:
a != b.
日本語
その他のゲート:NAND, NOR, XOR
- NAND は
not (a and b)です;NOR はnot (a or b)です。 - XOR は入力が異なる場合にTrueとなる:
a != b。
English
In the exam: logic gates
- Know the gates NOT, AND, OR, NAND, NOR, XOR and their truth tables.
日本語
試験における論理ゲート
- NOT, AND, OR, NAND, NOR, XOR の各ゲートと、その真値表を理解する。
X ← A AND B
Y ← NOT (A OR B)
English
Common mistakes
ANDis true only when both inputs are true;ORis true when at least one is.NOTflips the value.- A truth table lists every combination of the inputs.
日本語
よくあるミス
ANDは両方の入力が真の場合にのみ真です;ORは少なくとも片方が真の場合に真です。NOTは値を反転させる。- 真値表は入力のすべての組み合わせをリストする。
English
Now you try
- Each function returns the gate's Boolean output.
- Press Check answer to test your code.
日本語
あなたも試してみよう
- 各関数はゲートのブール出力を返す。
- 回答を確認 を押してコードを試してください。
Write AND_gate(a, b) that returns True only when both inputs are True.
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
Write XOR_gate(a, b) that returns True when the two inputs are different, and False when they are the same.
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
Write NAND_gate(a, b) that gives the opposite of AND: True unless both inputs are True. Use not (a and b).
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。