Why study? GC3 Boolean Algebra Computers transfer and process binary representations of data. Binary operations are easily represented and manipulated in Boolean algebra! Digital electronics is binary/boolean based. Boolean Values Boolean algebra has only 2 values: true, false true has these other representations: T, false has these other representations: F, Boolean Variables A Boolean variable (a, b, Out) holds a single boolean value
Boolean Functions Function of boolean values and Boolean variables:- e.g with boolean variables a, b, c, d, e, f(a,b) = a.b : f is function of boolean variables a, b g(c,d,e) = c.(d +e) :g is function of boolean variables c, d, e. and + are boolean operators and and or respectively and is often represented by ^ as well as by. e.g. a.b = a ^ b = a and b or is often represented by v as well as by + e.g. a+b = a v b = a or b
Table Representation of Boolean Functions To the right is a truth table It shows how the function f(a,b) maps its inputs (a, b) to its output f(a,b). Each boolean variable can only have one of 2 values, so there are only 4 (2x2) possible input combinations of 2 boolean variables. Thus, this truth table completely defines all possible input-ouput combinations for this function f(a, b). Often a function, e.g. f(a,b) will be given the name of a boolean variable, e.g. c, so that we can redraw the truth table as shown right a b f(a,b) a b c
Basic Boolean Functions Function Name syntax truth table Not (inversion function) f(a) = not(a) = a a a AND NAND Circuit symbol Circuit symbol Note: nand(a,b) = not(and(a,b)) nand (a,a) = not(a) f(a, b) = and(a,b) = a.b f(a, b) = nand(a,b) = a.b a b a.b a b a.b
Basic Boolean Functions Function Name syntax truth table OR Note: sometimes call inclusive-or to differentiate from exclusive-or NOR Note: nor(a,b) = not(or(a,b)) nor (a,a) = not(a) f(a, b) = or(a,b) = a+b f(a, b) = nor(a,b) = a+b a b a+b a b a+b
Basic Boolean Functions Function Name syntax truth table XOR (exclusive-or) f(a, b) = xor(a,b) = a b Note: it is called exclusive-or to differentiate from inclusive or xor(a,a) = NXOR f(a, b) = nxor(a,b) = Note: nxor(a,b) = not(xor(a,b)) xnor (a,a) = a b N.B There are 6 functions of 2 boolean variables: and, nand, or, nor, xor, nxor, not are just 7 of the possible 6. a b a b a b a b
Function Representation by and, or and not The equation and truth table to the left are the same function. The equation can be obtained from the truth table to the left. How? Generate an and term for each row in the table with an output using the inputs,e.g not(a) and b, 2 or all the and terms together. You can read the table or the equation as reading: F(a,b) = when a.b= or a.b= f(a,b) = a.b + a.b a b f(a,b) a b a.b a b a.b a.b + a.b f(a,b)
Alternative Function Representation by and, or and not f(a,b) = (a + b). (a + b) a b f(a,b). Generate an or term for each row in the table with output, such that the or term produces a e.g. (a + b) = if a = b = (a + b) = for a=, b=. 2. and all the or terms together. F(a,b) = when a+b= or a+b= a b a+b a b a+b (a+b).(a+b) f(a,b)
Rules of Boolean Algebra or rules: and rules: + = + = + =. =. =. = Let a, b, c be boolean variables:- or rules: and rules: a + a.b = a a+ = +a = a+ = + a =a a. =.a = a a. = a. = a + a = a a. a = a a + a = a. a = a.(b + c) = a.b +a.c = b.a + c.a = (b+c).a Proof: a + a.b = a. + a.b = a.(+b) = a. = a
Function to right can be represented by both: f(a,b) = a.b + a.b f(a,b) = (a + b). (a + b) Check equivalence:- f(a,b) = (a + b). (a + b) f(a,b) = (a + b).a + (a + b).b = a. a + b. a + a.b + b.b = + b. a + a.b + b = + b. (a + a) + b = + b. + b = b + b = b a b f(a,b) f(a,b) = a.b + a.b f(a,b) = (a + a).b f(a,b) =.b f(a,b) = b These are examples of minimisation of boolean functions.
De Morgan s Theorems a.b = a + b not the variables 2 swap and for or 3 not the lot Consistency check a + b = a. b not the variables 2 swap or for and 3 not the lot a.b = a + b = (a + b) = a.b = a.b first rule group apply 2 nd rule to a + b Remove double inversions
Binary Addition Equation for adding 2 bits from 2 binary numbers for the i th bits:- r i + s i + c i = c i+.2 + t i r i and s i are the i th bits from the 2 numbers to be added. c i is the carry-in to the addition from the addition of the i- th bits c i+ is the carry out to the addition of the i+ th bits t i is the i th bit of the result bit c i r i s i t i c i+ Can express results of addition as 2 boolean functions:- t i = c i (r i s i ) c i+ = c i.(r i +s i ) + c i.r i.s i
Circuit for generation of results of addition of 2 bits with carry in:- 2-input xor gates r i s i r i s i t i t i = c i (r i s i ) c i 2-input or gates r i +s i c i.(r i +s i ) c i+ c i.r i.s i inverter gate 2-input and gate 3-input and gate c i+ = c i.(r i +s i ) + c i.r i.s i Full Bit Adder Circuit
4-bit Adder Each block is one full bit adder from previous slide. Need 4 blocks for 4 bit addition. c is set to Present 4-bit numbers on A and B inputs and result will appear on outputs just add more blocks to add larger number v A B A B A 2 B 2 A 3 B 3 c r o s o r c t sum s c 2 c r 2 2 c sum t 2 sum 2 s 2 c 3 c r 3 3 t o t 3 sum 3 s 3 c 4
Subtraction Don t build subtraction unit, but use 2 s complement to modify adder to perform subtraction. To do A-B, invert bits of B and add via c 2-input multiplexer: S = input output S = input output Add selectop = Subtract selectop = selectop A B A B A 2 B 2 2-input multiplexers A 3 B 3 s s s s s c in c out sum c in c out sum c in c out sum 2 c in c out sum 3
Two-input multiplexer (mux) allows of 2 inputs on to output Value ( or ) on s controls which input c or d goes to out c d s out Truth table for multiplexer (X is don t care) s c d out X X X X c drives output d drives output Boolean function for multiplexer: out = s.c + s.d Note: you now know how to build binary add/subtract unit from basic gates: and, or, not (xor is built from these)