- Home
- Binary arithmetics
- Intel 8080 details, under construction
- Links

A boolean operator is basically a logic gate, or for the programmers amongst us a function which takes two arguments A and B. A and B are both binary numbers, which means that they can either be true or false. For an electronical circuit like your home computer this means physically, that there can either be current or no current.

The AND operator is a logical conjunction of A and B.
This function is referred to as the AND operator because it is only **TRUE IF A AND B ARE TRUE**.

The following chart will summarize the results for the AND operation.

A | B | Result |
---|---|---|

0 | 0 | 0 |

0 | 1 | 0 |

1 | 0 | 0 |

1 | 1 | 1 |

The OR operator is a logical disjunction of A and B.
This function is referred to as the OR operator because it is **TRUE IF EITHER A OR B ARE TRUE**.

The following chart will summarize the results for the OR operation.

A | B | Result |
---|---|---|

0 | 0 | 0 |

0 | 1 | 1 |

1 | 0 | 1 |

1 | 1 | 1 |

The NOT operator is a logical negation of only one binary value A.
This function is referred to as the NOT operator because it is only **TRUE IF NOT A IS TRUE**.

The following chart will summarize the results for the NOT operation.

A | Result |
---|---|

0 | 1 |

1 | 0 |

The XOR operator is an exclusive disjunction of A and B.
The XOR operator can most simply be described as follows: It is only **TRUE IF A, B ARE DIFFERENT**.

The following chart will summarize the results for the XOR operation.

A | B | Result |
---|---|---|

0 | 0 | 0 |

0 | 1 | 1 |

1 | 0 | 1 |

1 | 1 | 0 |

To calculate binary numbers more than one wire is laid side by side. Now let's begin by adding some single-digit binary numbers and see what problems we will encounter. See also: Adder (electronics)

A | B | Sum | Carry |
---|---|---|---|

0 | 0 | 0 | 0 |

0 | 1 | 1 | 0 |

1 | 0 | 1 | 0 |

1 | 1 | 0 | 1 |

It seems obvious that, within a single-digit result a "Sum" seems to be the same as a XOR operation.
The problem begins when both bits are true, because we have to go on with a carry bit
(and while A_{2} and B_{2} may both be true already we won't be able to cheat the carry in there either!).
The carry has influence on every subsequent bits to calculate, and each of them will be given a carry bit.
Let's have a look at the results chart.

Carry_{previous} | A | B | Sum | Carry_{next} |
---|---|---|---|---|

0 | 0 | 0 | 0 | 0 |

0 | 0 | 1 | 1 | 0 |

0 | 1 | 0 | 1 | 0 |

0 | 1 | 1 | 0 | 1 |

1 | 0 | 0 | 1 | 0 |

1 | 0 | 1 | 0 | 1 |

1 | 1 | 0 | 0 | 1 |

1 | 1 | 1 | 1 | 1 |

The first four lines will be plausible, since the results are the same as above. The other lines, marked in red give us
completely different results. Regarding A and B the effect on the sum part is NOT(A XOR B),
and for the carry it's A OR B.

The following chart shows the circuit for the full adder
from Wikipedia.

**S = (A XOR B) XOR C _{in}**

The carry is either set if both a and be or both the "sum" and C

To calculate binary subtraction, I will first introduce negative values of binary numbers, because subtraction can basically
be cut short as an addition with *negative* numbers. To calculate numbers negatively, we will use one
(the most significant) bit of the number as a "sign bit".

Binary | Unsigned | Signed |
---|---|---|

0000 | 0 | 0 |

0001 | 1 | 1 |

0010 | 2 | 2 |

0011 | 3 | 3 |

0100 | 4 | 4 |

0101 | 5 | 5 |

0110 | 6 | 6 |

0111 | 7 | 7 |

1000 | 8 | -8 |

1001 | 9 | -7 |

1010 | 10 | -6 |

1011 | 11 | -5 |

1100 | 12 | -4 |

1101 | 13 | -3 |

1110 | 14 | -2 |

1111 | 15 | -1 |

The trick seems plausible, as soon as someone came up with it. The problem is that the range of values must be reallocated.
This means, that any number less than -8 and bigger than 7, so instead of deactivating bit 4 (**15+1 != 0 / 0-1 != 15**),
activation of bit 4 will toggle the overflow flag (**7+1 != -8 / -8-1 != 7**).

The above example covers any wider integers' range to according values, as shown in the following table.

Width (in bits) | Unsigned range | Signed range |
---|---|---|

8 | from 0 to 255 | from -128 to 127 |

16 | from 0 to 65535 | from -32768 to 32767 |

32 | from 0 to 4294967295 | from -2147483648 to 2147483647 |

64 | from 0 to 18446744073709551615 | from -9223372036854775808 to 9223372036854775807 |

(GPL Copyleft) Martti Kühne, 26.8.2008