Lect 3 Number System, Gates, Boolean Algebra CS22: Digital Design Dr. A. Sahu Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati Outline Number System Decimal, Binary, Octal, Hex Conversions Operations: Add, Sub, Mul, Div, Complement Gates in Digital System Basic Gates (AND, OR & NOT) Universal Gates (NAND & NOR) Others : XOR, XNOR Boolean Algebra Axioms Boolean Functions 2 Number System Number System Decimal, Binary, Octal, Hex Conversion (one to another) Decimal to Binary, Octal, Hex & Vice Versa Binary to HEX & vice versa Other representation Signed, Unsigned, Complement Operation Add, Sub, Mul, Div, Mod 3 What Digit? => Number System Famous Number System: Decimal, Binary, Octal, Hexa decimal Decimal System: 9 May evolves: because human have finger Binary System, Others (Oct, Hex) 4 Significant Digits Decimal (base ) Binary: Most significant digit Least significant digit Decimal: 6379 Most significant digit Least significant digit Uses positional representation Each digit corresponds to a power of based on its position in the number The powers of increment from,, 2, etc. as you move right to left,479 = * 3 + 4 * 2 + 7 * + 9 *
Binary (base 2) Two digits:, To make the binary numbers more readable, the digits are often put in groups of 4 = * 2 3 + * 2 2 + * 2 + * 2 = + 2 = = *2 7 + *2 6 + *2 3 + *2 = 2 + 64 + + = 2 How to Encode Numbers: Binary Numbers Working with binary numbers In base ten, helps to know powers of one, ten, hundred, thousand, ten thousand,... In base two, helps to know powers of 2 one, two, four, eight, sixteen, thirty two, sixty four, one hundred twenty eight Count up by powers of two 2 9 2 2 7 2 6 2 5 52 256 2 64 32 2 4 2 3 2 2 2 2 6 4 2 a Octal (base ) Shorter & easier to read than binary digits:,, 2, 3, 4, 5, 6, 7, Octal numbers 36 = * 2 + 3* + 6* = *64 + 3* + 6 * = 94 Hexadecimal (base 6) Shorter & easier to read than binary 6 digits:,, 2, 3, 4, 5, 6, 7,, 9, A, B, C, D, E, F x often precedes hexadecimal numbers x23 = *6 2 + 2*6 + 3*6 = *256 + 2*6 + 3* = 256 + 32 + 3 = 29 Counting Decimal Binary Octal Hexadecimal Counting Decimal Binary Octal Hexadecimal 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 9 9 2 A 3 B 2 4 C 3 5 D 4 6 E 5 7 F 6 2 2 2
Fractional Number Point: Decimal Point, Binary Point, Hexadecimal point Decimal 247.7575 = 2x 2 +4x +7x +7x +5x 2 Fractional Number Point: Decimal Point, Binary Point, Hexadecimal point Binary.= = x2 +x2 +x2 +x2 2 +x2 3 Hexadecimal 6A.7D=6x6 +x6 +7x6 +Dx6 2 Converting To and From Decimal Decimal Binary Octal 2 3 4 5 6 7 Decimal 2 3 4 5 6 7 9 Binary 2 Hexadecimal 6 2 3 4 5 6 7 9 A B C D E F a) Divide the decimal number by 2; the remainder is the LSB of the binary number. b) If the quotation is zero, the conversion is complete. Otherwise repeat step (a) using the quotation as the decimal number. The new remainder is the next most significant bit of the binary number. 5 Decimal Binary a)multiply each bit of the binary number by its corresponding bit weighting factor (i.e., Bit 2 =; Bit 2 =2; Bit 2 2 2 =4; etc). b)sum up all of the products in step (a) to get the decimal number. Decimal to Binary : Subtraction Method Goal Good for human Get the binary weights to add up to the decimal quantity Work from left to right (Right to left may fill in s that shouldn t have been there try it). Desired decimal number: 2 32 6 4 2 =32 32 6 4 2 too much =6 32 6 4 2 too much = 32 6 4 2 ok, keep going =+4=2 32 6 4 2 DONE answer 32 6 4 2 a 3
Decimal to Binary : Method Good for computer: Divide decimal number by 2 and insert remainder into new binary number. Continue dividing quotient by 2 until the quotient is. Example: Convert decimal number 2 to binary 2 div 2 = ( Quo=6, Rem=) LSB 6 div 2 = (Quo=3, Rem=) 3 div 2 = (Quo=,Rem=) div 2 = ( Quo=, Rem=) MSB 2 = 2 Conversion Process Decimal Base N a) Divide the decimal number by N; the remainder is the LSB of the ANY BASE Number. b) If the quotient is zero, the conversion is complete. Otherwise repeat step (a) using the quotient as the decimal number. The new remainder is the next most significant bit of the ANY BASE number. a) Multiply each bit of the ANY BASE number by its corresponding bitweighting factor (i.e., Bit N ; Bit N ; Bit 2 N 2 ; etc). b) Sum up all of the products in step (a) to get the decimal number. Decimal Octal Conversion The Process: Divide number by ; R is the LSB of the octal number While Q is Using the Q as the decimal number. New remainder is MSB of the octal number. 94 r = 6 LSB r = 3 r = MSB 94 = 36 2 Decimal Hexadecimal Conversion The Process: Divide number by 6; R is the LSB of the hex number While Q is Using the Q as the decimal number. New remainder is MSB of the hex number. 6 6 5 94 5 r = E LSB r = 5 MSB 94 = 5E 6 Example: Hex Octal Example: Convert the hexadecimal number 5A H into its octal equivalent. Solution: First convert the hexadecimal number into its decimal equivalent, then convert the decimal number into its octal equivalent. 5 A 9 r = 2 LSB 6 6 6 r = 3 + = 9 r = MSB 5A H = 32 23 Example: Octal Binary Example: Convert the octal number 32 into its binary equivalent. Solution: First convert the octal number into its decimal equivalent, then convert the decimal number into its binary equivalent. 3 2 2 64 64 + 24 + 2 = 9 45 2 9 22 2 45 2 22 5 2 2 2 5 2 2 2 r = LSB r = r = r = r = r = r = MSB 32 = 2 24 4
Binary Octal Hex Shortcut Relation Binary, octal, and hex number systems All powers of two Exploit (This Relation) Make conversion easier. Substitution Code Convert 2 to hex using the 4 bit substitution code : 5 6 A E 6 A 56AE6A 6 25 Substitution Code Substitution code can also be used to convert binary to octal by using 3 bit groupings: 2 5 5 2 7 5 2 2552752 Conversion of Fractional Number Convert 63.75 to binary Integer part 63/2=>/2=>4/2=>2/2=>/2=>5/2=>2/2=> LSB Integer part: Fractional part.75*2=.75 =>.75*2=.5 =>.5*2=. Fractional part :. Total :. 2 Conversion of Fractional Number Convert.5 to binary Fractional part.5*2=.3 =>.3*2=.6 => 6*2.6 = 2.2 =>.2*2 =.4 =>.4*2 =. =>.*2 =.6 =>.6*2 =>. Repeating sequences Total :.. Other Representation Signed & Unsigned Number Signed number last bit (one MSB) is signed bit Assume: bit number Unsigned 2 : Signed +2 : Signed 2 : Complement number Unsigned binary 2 = s Complement of 2 = 29 3 5
Operations on Numbers Addition Substraction Binary Addition ne bit + = + = + = + = (Carry bit) Multibit (consider carry) + = 3 Binary Subtraction ne bit = = = (Carry bit) = Multibit (consider carry) = Subtraction 9 s complement and s complement Suppose Decimal two digit System Max number 99, Min = Substation : 55 33= 22 [55 + ( 33)] %= [55+67]%= [22]%=22 Tow s complement in Dec 99 33+ == 33 Binary Subtraction Multibit (consider carry) = Add 2 s complement= () += += Other way (add 2 s complement & discard carry) + = 2 s complement examples Express 45 in bit 2 s complement form +45 in bit form Complement it = Add to it = + 2 s complement = 36 6
Binary Repeated addition Many improved technique (Famous Partial Sum) = X =7 = + + + + = 56 37 Binary Repeated addition Many improved technique [7 is ] = X =7 = + + + + = 56 3 Binary Repeated addition Many improved technique [7 is ] = X + =7 = + + + = 56 39 Binary Booth Methods + + + Binary & Modulus = 5 3 ) ( ( ( ( ( Q==6 R== 2 ( 4 Hex Addition Addition + A + 2 B + 7 C A 6 = 9 6 D Subtraction +6 A 2 B 9 C F 3 5 C 6 Carry Value to higher significant one is 42 7
Boolean Algebra Boolean Algebra Computer hardware using binary circuit greatly simply design George Boole (3-64): developed a mathematical structure in 47 To deal with binary operations with just two values Binary circuits: To have a conceptual framework to manipulate the circuits algebraically Claude Shannon : 937, Master Thesis Basic Gates in Binary Circuit Element : FALSE. Element : TRUE. + operation OR, * operation AND and operation NOT. OR AND NOT 45 OR Gate + operation OR X Y R=X+Y OR X Y R=X OR Y R= X + Y + Y = 46 AND Gate * operation AND X Y R=X AND Y X Y R=X*Y AND R= X * Y * Y = 47 NOT Gate operation NOT or use BAR R= X R=X X X R=X R= NOT X 4
Boolean Algebra Defined Boolean Algebra B : 5-tuple {B, +, *,,, } + and * are binary operators, is a unary operator. Boolean Algebra Defined Axiom #: Closure If a and b are Boolean (a + b) and (a * b) are Boolean. Axiom #2: Cardinality/Inverse if a is Boolean then a is Boolean Axiom #3: Commutative (a + b) = (b + a) (a * b) = (b * a) Boolean Algebra Defined Axiom #4: Associative : If a and b are Boolean (a + b) + c = a + (b + c) (a * b) * c = a * (b * c) Axiom #6: Distributive a * (b + c) = (a * b) + (a * c) a + (b * c) = (a + b) * (a + c) Thanks 2 nd one is Not True for Decimal numbers System 5+(2*3) (5+2)*(5+3) 56 52 9