EE210: Switching Systems Lecture 3: Binary Subtraction, Switching Algebra, Gates, and Algebraic Expressions Prof. YingLi Tian Feb. 5/7, 2019 Department of Electrical Engineering The City College of New York The City University of New York (CUNY) 1
Outlines Quick Review of the Last Lecture Switching Algebra Gates Algebraic Expressions Course Web-page: http://medialab.ccny.cuny.edu/wordpress/yltccnyh omepage/ee2100.html 2
Covered In Last Lecture Convert positive binary integers (unsigned) to decimal Convert decimal to positive binary integers (unsigned) Add (Subtraction ) two numbers together Unsigned Signed 3
Signed Numbers Signed binary numbers use the first bit as a sign indicator (normally 0 for positive and 1 for negative). Signed binary numbers are stored in two s complement format. Unsigned 4
Two s Complement Format for Negative Numbers Step 1: Find the binary equivalent of the magnitude Step 2: Complement each bit (that is, change 0 s to 1 s and 1 s to 0 s) Step: Add 1 Example 1: How to find the binary representation of a negative number. -5, 1) find 5: 0101; 2) Complement each bit; 3) add 1; 4) -5: 1011 Example 2 : How to find the magnitude of a negative binary number? 1011, 1) bit-by-bit complement, 2) add 1; 3) 0101 (5) 5
Overflow Overflow occurs when the sum is out of range. Can occur for both unsigned and signed numbers. For example: A 4-bit unsigned number: range [0, 15] A 4-bit signed number: range [-8, +7] Tips: For signed number, there is an overflow if: Two positive numbers result a negative sum, or Two negative numbers result a positive sum Practice: Example 1.16 (p13) (5 + 4) Example 1.17 (p14) (-5) + (-4) 6
Binary Subtraction a-b is computed as a+(-b). See Example 1.18 (Page 14): 7-5 = 7 + (-5) When doing addition or subtraction, two numbers must be both signed or unsigned. For unsigned number subtraction, overflow will happen if the carry out of the highorder bit is 0. For signed numbers, the carry out of the high-order bit is ignored. 7
Binary Subtraction Practice 5 3 unsigned numbers, if overflow? a) Use 3 bits, b) use 4 bits 3 5 unsigned numbers, if overflow? a) Use 3 bits, b) use 4 bits 5 3 signed numbers, if overflow? a) Use 4 bits, b) use 5 bits 3 5 signed numbers, if overflow? a) Use 4 bits, b) use 5 bits For signed numbers, can use 3 bits? 8
Binary Subtraction Practice 5 3 unsigned numbers, No overflow! a) Use 3 bits 101 + 101 = (1) 010, b) use 4 bits -- 0101 + 1101 = (1) 0010 3 5 unsigned numbers, Overflow! a) Use 3 bits, 011 + 011 = (0) 110, b) use 4 bits: 0011 + 1011 = (0) 1110 5 3 signed numbers, No overflow! a) Can use 4 bits? 0101 + 1101 = (1) 0010, b) use 5 bits -- 00101 + 11101 = (1) 00010 3 5 signed numbers, No overflow! a) Use 4 bits 0011 + 1011 = 1110, b) use 5 bits 00011 + 11011 = 11110 9
Combinational Logic Combinational logic has no memory (see Example 1)! Outputs are only function of current input combination Nothing is known about past events Repeating a sequence of inputs always gives the same output sequence 10
Design Combinational Systems Step 1: Represent each of the inputs and outputs in binary Step 2: Formalize the design specification either in the form of a truth table or of an algebraic expression Step 3: Simplify the description Step 4: Implement the system with the available components, subject to the design objective and constrains. 11
Truth Table A system with two inputs, A and B, and one output, Y. The output Y = 1 if any of the input is 1. 12
Don t Care Conditions For a system, the output is specified for only some of the input conditions. For the remaining input combinations, we don t care. In a truth table, we use X for don t care. 13
Design a System with Don t Care Can be one of the outputs, for example, in Table 2.3, can be either f1 or f2. Choose the one with less cost. In system design, Don t cares occur: The combination will never happen. For example, a bank alert system, only when you money <= 0, send out the alert. The design of one system to derive a second system (Handle in Chapter 7) 14
Truth Table Development Example CE1: A system with four inputs, A B, C, and D, and one output, Z, such that Z=1 iff (if and only if) three of the inputs are 1. Z1 is the correct answer of CE1 15
Design of a 7-segment display -- 1 A system displays a decimal digit (0-9) to a 7-segment display. 16
Design of a 7-segment display -- 2 17
Switching Algebra Why need Switching Algebra? Creating a whole truth table is slow Algebra allows us to simplify the expression of complex system Algebra can enable us to satisfy the constrains of a problem Switching algebra is binary All variables and constants take on one of two values: 0 and 1 18
Definition of Switching Algebra OR (written as +) a + b (read a OR b) is 1 if a = 1 or b = 1 or both. AND (written as ) a b = ab (read a AND b) is 1 if and only if a = 1 and b = 1. NOT (written as ) a (read NOT a) is 1 if and only if a = 0. 19
Gates A gate is a circuit with one output that implements one of the basic functions such as OR and AND, but the input can be 2, 3, 4 or 8. 20
Typical Gates 21
Properties of Switching Algebra -- 1 Commutative: P1a: a + b = b + a P1b: ab = ba Associative: P2a: a + (b + c) = (a + b) + c P2b: a(bc) = (ab) c Identity: P3a: a + 0 = a P3b: a 1 = a Null: P4a: a + 1 = 1 P4b: a 0 = 0 22
Properties of Switching Algebra -- 2 Complement: P5a: a + a = 1 P5b: a a = 0 Idempotency: P6a: a + a = a P6b: a a = a Involution: P7: (a ) = a Distributive: P8a: a (b + c) = ab + ac P8b: a + bc = (a + b)(a + c) 23
Properties of Switching Algebra -- 3 Adjacency: P9a: ab + ab = a P9b: (a + b)(a + b ) = a Simplification: P10a: a + a b = a + b P10b: a(a + b) = ab DeMorgan: P11a: (a + b) = a b P11b: (ab) = a + b P11aa: (a + b + c ) = a b c P11bb: (abc ) = a + b + c + Distributive: P12a: a + ab = a P12b: a(a + b) = a 24
Verify properties by constructing a truth table P8b: a + bc = (a + b)(a + c) 25
Order of precedence: Parentheses expressions inside the parentheses are evaluated first. If without parentheses: 1) NOT ; 2) AND; 3) OR Example: ab + c d = [a(b )] + [(c )d] 26
Gate Implementation P2b: a(bc) = (ab) c P2a: a + (b + c) = (a + b) + c Who want to implement it? 27
Announcement: HW1 is due Feb. 14. Review Chapter 2.2 Next class (Chapter 2.3-2.5): Implementation AND, OR, NOT Gates Complement Truth table to algebraic expressions 28