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.
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.
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.
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.
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)
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 A2 and B2 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.
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 Cin
The carry is either set if both a and be or both the "sum" and Cin are set.
Cout = (A AND B) OR ((A XOR B) AND Cin)
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".
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