TRUTH TABLES FOR BOOLEAN OPERATIONS These tables give the results of applying the operator 'not' to a single boolean value, and the operators 'and', 'or', 'xor' and 'nand' to two boolean values. 'nand' has been included here, because it will be shown later that all the other operators can be defined in terms of the single operator 'nand'. A not(A) - ------ false true true false A B A and B A or B A xor B A nand B - - ------- ------ ------- -------- false false false false false true true false false true true true false true false true true true true true true true false false REWRITE RULES OF BOOLEAN ALGEBRA By inspection of the truth tables, it can be shown that any expression on the left hand side of a rule can be replaced by the expression on the right hand side of the same rule, and vice versa. 1. A <--> A and A 2. A <--> A or A 3. A <--> not(not(A)) 4. not(A and B) <--> not(A) or not(B) 5. not(A or B) <--> not(A) and not(B) 6. A or (B and C) <--> (A or B) and (A or C) 7. A and (B or C) <--> (A and B) or (A and C) 8. false and A <--> false 9. false or A <--> A 10. true and A <--> A 11. true or A <--> true 12. A and not(A) <--> false 13. A or not(A) <--> true The remaining three rules give the definitions of 'xor', 'nand', and 'nor'. 14 A xor B <--> (A or B) and not(A and B) 15. A nand B <--> not(A and B) 16. A nor B <--> not(A or B) REPRESENTATION OF BOOLEAN OPERATIONS IN TERMS OF 'NAND' AND 'NOT' Using the rewrite rules, each boolean operation can now be expressed as a combination of 'nand' and 'not'. 'not' itself can be expressed in terms of 'nand'. The numbers in brackets on the right refer to the rewrite rules used in each step. not(A) --> not(A and A) (1) --> A nand A (15) A and B --> not(not(A and B)) (3) --> not(A nand B) (15) A or B --> not(not(A)) or not(not(B)) (3) --> not(not(A) and not(B)) (4) --> not(A) nand not(B) (15) A xor B --> (A or B) and not(A and B) (14) --> (A or B) and (not(A) or not(B)) (4) --> (A and not(A)) or (A and not(B)) or (B and not(A)) or (B and not(B)) (6 and 7) --> false or (A and not(B)) or (B and not(A)) or false (12) --> (A and not(B)) or (B and not(A)) (9) --> not(A and not(B)) nand not(B and not(A)) (19) --> (A nand not(B)) nand (B nand not(A)) (15) The expansions of the boolean operations derived above are then: 17. not(A) --> A nand A 18. A and B --> not(A nand B) 19. A or B --> not(A) nand not(B) 20. A xor B --> (A nand not(B)) nand (B nand not(A)) CONSTRUCTION OF LOGIC GATES Boolean values are represented inside digital computers by voltage levels. For example, 'false' might be 0 volts and 'true' might be 5 volts (relative to earth). Logical operations are performed by logic gates. A logic gate accepts one or more boolean values (represented by voltage levels) as input, and gives one or more boolean values (again, represented by voltage levels) as output. The most widely used logic gate is called a transistor-transistor logic (TTL) gate. This is, in fact, a 'nand' gate. All other boolean logic gates can be constructed from TTL gates. For an operation 'X op Y', the inputs to the 'op' logic gate are (X) and (Y), and the output is (X op Y). From (17), the single input of 'not' is (A) and its output is (A nand A). A 'not' gate is simply a 'nand' gate with two identical inputs. ________ ____! ! A -------!____! nand !------- not(A) !________! From (18), the inputs of 'and' are (A) and (B), and its output is not(A nand B). (A) and (B) are accepted as input into a 'nand' gate and an intermediate output (A nand B = P), is produced. (P) is then accepted as input into a 'not' gate (shown above), which outputs the final result of not(P) = not(A nand B) = (A and B). _________ ________ A________! ! P ____! ! ________! nand !-------!____! nand !-------- A and B B !_________! !________! The 'or' gate and the 'xor' gate can be similarly constructed using (19) and (20), and are shown below. ________ ____! ! not(A) A -----!____! nand !-----+ ________ !________! !_____! ! ________ _____! nand !--- not(A) nand not(B) ____! ! ! !________! = A or B B -----!____! nand !-----+ !________! not(B) ________ ________ ___! ! ____! ! not(A) nand B A ---!___! nand !---/ __! nand !---+ !________! !________! ! ! ________ !___! ! ___! nand !--- A xor B ! !________! ________ ________ ! ___! ! __! ! ! B ---!___! nand !--- ____! nand !---+ !________! !________! A nand not(B) THE HALF ADDER AND FULL ADDER The basic module used in binary arithmetic elements is the half adder. Its function is to add two binary digits, producing a sum and a carry according to the following binary addition rules: Inputs Sum Bit Carry Bit ------ ------- --------- 0 + 0 0 0 0 + 1 1 0 1 + 0 1 0 1 + 1 0 1 Note that the sum bit is the 'xor' of the inputs, and that the carry bit is the 'and' of the inputs. The half adder consists of one 'xor' gate and one 'and' gate. _______ A _______________! ! __! xor !------- Sum Bit !_______! _______ __! ! B _______________! and !------- Carry Bit !_______! The term 'half adder' is used because addition of numbers consisting of more than one bit requires three inputs: a digit for each of the terms plus a carry from the sum of the previous two digits, as illustrated in the following sum. 1011 1011 + 1110 + 1110 ----- ----- 11001 sum 0101 Sum Bits + 10100 Carry Bits ----- 11001 complete sum The full adder can be constructed from two half adders and an 'or' gate: _________ P ________________________! !_____________________ sum _________ ! half ! A _______! !______! adder !______ ______ ! half ! S1 !_________! C2 !___! ! B _______! adder !___________________________! or !--- carry !_________! C1 !______! The carry from the previous adder (P) is added to the sum of the two binary digits (A) and (B). C1 and C2 cannot both be 1 simultaneously: either C1 is 0, or C1 is 1, in which case S1 is 0. If S1 is 0, then C2 must be 0. A 4-bit adder, composed of four full adders. Note that, since there was no carry input to the adder of the least significant bits, this adder could be replaced by a half adder. a3 b3 a2 b2 a1 b1 a0 b0 ! ! _ ! ! _ ! ! _ ! ! _____ 0 ! ! ! \ ! ! ! \ ! ! ! \ ! ! ! ! ! \ ! ! \ ! ! \ ! ! ! + ! \ ! + ! \ ! + ! \ ! + ! !_____! \ !_____! \ !_____! \ !_____! __! ! \__! ! \__! ! \__! ! C ! ! ! ! s3 s2 s1 s0