# Truth tables for logic operations

## Truth table for "NOT"

A | Result
--- | ---
0 | 1
1 | 0

A bit-wise NOT operation performs the logical NOT operation on each bit of the input.

i.e.
bit 7result = NOT bit 7input ,
bit 6result = NOT bit 6input ...

For the 8-bit value 10110011 (base 2), this table shows the computation:

| Bit
--- | ---
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
Input | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1
Result | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0

An example in Z80 assembler:

    ld a,%10110011        ;; load value into A register
    not                   ;; perform bit-wise logical NOT operation on all bits of register A

## Truth table for "AND"

A | B | Result
--- | --- | ---
0 | 0 | 0
0 | 1 | 0
1 | 0 | 0
1 | 1 | 1

A bit-wise AND operation performs the logical AND operation on each bit position of the input values.

i.e.
bit 7result = bit 7input A AND bit 7input B ,
bit 6result = bit 6input A AND bit 6input B ...

For two 8-bit values: inputA = 10110011 (base 2), inputB = 11101010, this table shows the computation:

| Bit
--- | ---
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
Input A | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1
Input B | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0
Result | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0

An example in Z80 assembler:

    ld a,%10110011        ;; load input A into A register
    ld b,%11101010        ;; load input B into B register
    and a,b               ;; A = A AND B (each bit of A is logically ANDed with each bit in B
                          ;; and the result is stored back into A)

## Truth table for "OR"

A | B | Result
--- | --- | ---
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 1

A bit-wise OR operation performs the logical OR operation on each bit position of the input values.

i.e.
bit 7result = bit 7input A OR bit 7input B ,
bit 6result = bit 6input A OR bit 6input B ...

For two 8-bit values: inputA = 10110011 (base 2), inputB = 11101010, this table shows the computation:

| Bit
--- | ---
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
Input A | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1
Input B | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0
Result | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1

An example in Z80 assembler:

    ld a,%10110011        ;; load input A into A register
    ld b,%11101010        ;; load input B into B register
    or a,b                ;; A = A OR B (each bit of A is logically ORed with each bit in B
                          ;; and the result is stored back into A)

## Truth table for "Exclusive-OR (XOR/EOR)"

A | B | Result
--- | --- | ---
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 0

A bit-wise XOR operation performs the logical XOR operation on each bit position of the input values.

i.e.
bit 7result = bit 7input A XOR bit 7input B ,
bit 6result = bit 6input A XOR bit 6input B ...

For two 8-bit values: inputA = 10110011 (base 2), inputB = 11101010, this table shows the computation:

| Bit
--- | ---
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
Input A | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1
Input B | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0
Result | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1

An example in Z80 assembler:

    ld a,%10110011        ;; load input A into A register
    ld b,%11101010        ;; load input B into B register
    xor a,b               ;; A = A XOR B (each bit of A is logically Exclusive-ORed with each bit in B
                          ;; and the result is stored back into A)