27..27 Chapter Binary Arithmetics Dr.-Ing. Stefan Werner Table of content Chapter : Switching Algebra Chapter 2: Logical Levels, Timing & Delays Chapter 3: Karnaugh-Veitch-Maps Chapter 4: Combinational Circuit Design Chapter 5: Latches and Flip Flops Binary Addition of Chapter 6: Finite State Machines unsigned Chapter 7: State Machine Minimization Binary Subtraction of Chapter 8: Basic Sequential Circuits Chapter 9: Number Systems Chapter : Binary Arithmetic Chapter : Binary Codes unsigned Addition and Subtraction of signed Binary Multiplication 2of 23
27..27 Binary addition of unsigned Binary Arithmetic is basically the same as the arithmetic in every other number system. Considering two bits to be added there are only four possible cases: + = + = += + = Every bit has its position, the case + produces a carry occurring in the next position. 3of 23 Binary addition of unsigned The addition of whole is done bitwise from the least significant bit (LSB) to the most significant ifi bit (MSB): 34 + + 92 ++= += += += 4of 23 2
27..27 Binary addition of unsigned The addition of whole is done bitwise from the least significant bit (LSB) to the most significant bit (MSB): 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 2 34 + + 92 2568 + 6 + 4 + 2 = 46 5of 23 Problem: in theory: there exist as many digits as needed to represent a number in real life: there is only a limited number of digits in a system. Consider two summands of n-bit length with a resulting addition of only s in the MSB this addition of the two n-bit produces a result with (n+) bits in the given systems the result is out of the range that could be represented with the original word length. this occurrence of a carry in the most significant position is called overflow. 6of 23 3
27..27 Example: Addition of 4 bit yielding an overflow 6 + + 7 7of 23 Binary subtraction of unsigned Likewise the addition, the subtraction can lead to a borrow bit in the next position. Consider the following cases: = = = = Borrow = Borrow = Borrow 8of 23 4
27..27 Binary subtraction of unsigned Example 34-92 --= -= -= Borrow -= -= Borrow 9of 23 Binary subtraction of unsigned Example 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 2 34-92 28 +64 +6 + 8 + 4 + 2 = 222 of 23 5
27..27 Addition and subtraction of signed In digital circuits it is usually easier to invert the subtrahend and use an addition instead: Z Z 2 = Z +( Z 2 ) Now: Addition using the 2 s Complement Still the old problem: overflows can occur The 2 s Complement s addition can be visualized as running around the already known circle -2 - + + +6 of 23 Addition and subtraction of signed In this model, the overflow is nothing more than stepping from the negative to the positive half at the gateway / (consider + = = 2 + 2 = 2. A carry from the most significant position has to be discarded. Also: 2 s Complement s addition has a different overflow. 8 is just one step away from 7 the h addition i of two positive i can yield a negative one Consider: 2 + 2 = 2 7 + = - 8-2 - + + +6 2 of 23 6
27..27 Addition and subtraction of signed Discard carry An overflow in a 2 s Complement s addition can only occur if both - + are positive or both are negative. -2 + +6 3 of 23 Addition and subtraction of signed Examples Discard carry Addition without overflow MSB + 2 + - + -2 + +6 4 of 23 7
27..27 Addition and subtraction of signed Examples Discard carry Addition without overflow MSB - + + 4-2 + + +() Same as 3 + 4 +6 5 of 23 Addition and subtraction of signed Examples Addition without overflow Discard carry MSB 3 + +() -2-2 - + + +6 6 of 23 8
27..27 Addition and subtraction of signed Examples Discard carry Addition with overflow MSB 4 + Result not valid -2 - + + +6 + 7 of 23 Addition and subtraction of signed Examples Addition with overflow MSB + + (-2) 7 Result not valid -2 - Discard carry + + +6 - -2 8 of 23 9
27..27 Binary Multiplication Consider unsigned integer in the decimal system Example: a b multiply the factor a with each digit of b and multiply single results by powers of according to the n n digit s position i Z B = a b = a xi B = a x consecutively add the results i= m i= m 4 9 6 3 4 9 8 9 4 4 4 7 2 4 2 8 7 49 2 + 49 6 + 49 3 = 24.287 i B 9 of 23 i Binary Multiplication n n i i Example Z B = a b = a xi B = a xi B i= m i= m Binary system: x i is either or therefore a x i is either a or. the multiplication can be visualized in the same scheme as in case of the decimal system Fractional : multiplication is done the same way by just ignoring i the point during the multiplication li procedure. result has as many fraction digits as both factors together Example:.. =. 5 fraction digits, multiplication is the same as above 2 of 23
27..27 Binary multiplication of signed Signed in Sign-Magnitude-Representation cannot be multiplied directly split up into sign and magnitude both parts have to be treated t separately. magnitudes are multiplied as in case of unsigned resulting sign is determined from the signs of the factors: st factor 2 nd factor st sign bit 2 nd sign bit Result Result s sign bit Positive Positive Positive Positive Negative Negative Negative Positive Negative Negative Negative Positive A B C=A B 2 of 23 Binary multiplication of signed Example (word length 6 bit): 3 () = 2 2 Sign st factor A= Sign 2 nd factor B= Magnitude st factor Magnitude 2 nd factor Product of Magnitudes: = Sign of Result: C= 3 () = 22 of 23
27..27 Binary multiplication in 2 s complements Binary Multiplication in 2 s-complement representation cannot be done. Instead the are converted to Sign- Magnitude representation 23 of 23 2