ECE-8L: Computer Logic Design Fall Notes - Chapter BINARY NUMBER CONVERSIONS DECIMAL NUMBER SYSTEM A decimal digit can take values from to 9: Digit-b-digit representation of a positive integer number (powers of ): DIGIT 4 5 6 7 8 9 Number: 97 hundreds thousands tens units 9 7 9 thousands, hundreds, 7 tens, and units 97 = 9 + + 7 + Positional Number Representation Let s consider the numbers from to 999. We represent these numbers with digits (each digit being a number between and 9). We show a -digit number using the positional number representation: MATHEMATICAL REPRESENTATION -digit d d d EXAMPLE 9 Third Digit Second Digit First Digit The positional number representation allows us to epress the decimal value using powers of ten: D = d + d + d. Eample: Decimal Number 9 5 9 8 55 Eercise: Write down the -digit and the powers of ten representations for the following numbers: Decimal Number -digit representation d + d + d 5 54 99 -digit representation d d d 9 5 9 8 55 Third Digit Second Digit First Digit Powers of : d + d + d + + + + 9 + + + + 5 + 9 + + + 8 + 5 + 5
ECE-8L: Computer Logic Design Fall General Case: Positional number representation for an integer positive number with n digits: Decimal Value: d n- n- + d n- n- +... + d + d 6 5 4 Eample: 984 (7 digits). 984 9 8 4 5 4 476 (6 digits). 476 4 7 6 Maimum value: The table presents the maimum attainable value for a given number of digits. What pattern do ou find? Can ou complete it for the highlighted cases (4 and 6)? Number of digits Maimum value Range 9 = - 9-99 = - 99-999 = - 999-4 5 99999 = 5-99999 5-6 n 999 999 = n - 999 999 n - Maimum value for a number with n digits: Based on the table, the maimum decimal value for a number with n digits is given b: With n digits, we can represent positive integer numbers from to n -. d n- d n-... d d D = 999...999 = 9 n- + 9 n- +... + 9 + 9 = n - n digits With 7 digits, what is the range (starting from ) of positive numbers that we can represent? How man different numbers can we represent? BINARY NUMBER SYSTEM DIGIT BIT We are used to the decimal number sstem. However, there eist other number sstems: octal, headecimal, vigesimal, binar, etc. In particular, binar numbers are ver practical as the are used b digital computers. For 4 5 6 7 8 9 binar numbers, the counterpart of digit (that can take values from to 9) is the bit (binar digit) that can take the value of or. Bit: Unit of information that a computer uses to process and retrieve data. It can also be used as a logical variable (see Chapter ). Binar representation: We use the positional number representation. Note that here, we are using a string of bits to represent a binar number. Converting a binar number into a decimal number: The following figure depicts two cases: -bit numbers and -bit numbers. Note that the positional representation with powers of two let us obtain the decimal value (integer positive) of the binar number.
ECE-8L: Computer Logic Design Fall MATHEMATICAL REPRESENTATION -bit Second Bit b b First Bit Binar number b b Powers of : b + b + + + + Decimal Number MATHEMATICAL REPRESENTATION -bit b b b Third Bit Second Bit First Bit Binar number Powers of : Decimal Number b b b b + b + b + + + + + + + + + + + + + + + + 4 5 6 7 General case: Positional number representation for a binar number with n bits: Most significant (leftmost) bit b n- b n-... b b Least significant (rightmost) bit This formula converts a binar number into a decimal number: Decimal Value (integer positive): To avoid confusion, we usuall write a binar number and attach a suffi : (b n b n b b ) Eample: 6 bits: () D = 5 + 4 + + + + = 4 4 bits: () D = + + + = Maimum value for a given number of bits. Complete the tables for the highlighted cases (4 and 6): Number of bits Maimum value Range - - - - - - 4 5 5-5 - 6 D = b n- n- + b n- n- +... + b + b n n - n - Maimum value for n bits: The maimum decimal value with n bits is given b: D =... = n- + n- +... + + = n - n bits With n bits, we can represent positive integer numbers from to n -. ( n numbers)
ECE-8L: Computer Logic Design Fall The case n=8 bits is of particular interest, as a string of 8 bits is called a bte. Here, the range for 8-bit numbers is to 8 - to 55. b 7 b 6 b 5 b 4 b b b b Most significant (leftmost) bit Least significant (rightmost) bit The table shows some eamples: Decimal Number 9 5 9 8 55 8-bit format b 7 b 6 b 5 b 4 b b d d b 7 7 + b 6 6 + b 5 5 + b 4 4 + b + b + b + b 7 + 6 + 5 + 4 + + + + 7 + 6 + 5 + 4 + + + + 7 + 6 + 5 + 4 + + + + 7 + 6 + 5 + 4 + + + + 7 + 6 + 5 + 4 + + + + 7 + 6 + 5 + 4 + + + + 7 + 6 + 5 + 4 + + + + Eercise: Convert the following binar numbers (positive integers) to their decimal values: 8-bit representation b 7 7 + b 6 6 + b 5 5 + b 4 4 + b + b + b + b Decimal Number In general to convert a number of base 'r' (r =,,4, ) to decimal, we use the following formula: base 'r': (r n r n r r ) r Conversion to decimal: D = r n r n + r n r n + + r r + r r Also, the maimum decimal value for a number in base 'r' with 'n' digits is: D = rrr rrr = r r n + r n r n + + r r + r r = r n Eample: Base-8: Number of digits Maimum value Range 7 8 8-7 8 8-77 8 8-77 8 8-777 8 8-777 8 8 - n 777 777 8 8 n - 777 777 8 8 n - Eamples: (56) 8 : base 8 (octal sstem) Number of digits: n = 5 Conversion to decimal: D = 5 8 4 + 8 + 6 8 + 8 + 8 = 89 () 4 : base 4 (quaternar sstem) Number of digits: n = 4 Conversion to decimal: D = 4 + 4 + 4 + 4 =
ECE-8L: Computer Logic Design Fall CONVERSION OF DECIMAL TO BINARY NUMBERS Two eamples are shown: base base base base 5???????? 6 5 Remainder 6 Remainder 6 6 6 5 6 7 5 7 stop here! stop here! Note that some numbers require fewer bits than others. If we want to use a specific bit representation, e.g., 8-bit, we just need to append eros to the left until the 8 bits are completed. For eample: (8-bit number) (8-bit number) Actuall, ou can use this method to convert a decimal number into an other base. For eample, if ou want to convert it into a base-8 number, just divide b 8 and group the remainders. Eample: Converting a decimal number to base-8: base 8 8 8 Remainder base 8???? 8 8 8 8 stop here!
ECE-8L: Computer Logic Design Fall Eercise: Convert the following two decimal numbers to binar numbers. Fill in the blanks in the figure below. base base base base 6???? 97???? Remainder Remainder 6 97 Now, convert the following decimal numbers to binar numbers. The final binar number must have 8 bits (append eros to the left to complete). Decimal number 4 Binar number with 8 bits. b 7b 6b 5b 4b b b b 55 6 9
ECE-8L: Computer Logic Design Fall HEXADECIMAL NUMBERS In the decimal number sstem, a digit can take a value from to 9. In the headecimal number sstem, a headecimal digit can take a value from to 5. However, as to avoid confusion, the numbers from to 5 are represented b letters (A-F): HEXADECIMAL DIGIT Decimal value: A single headecimal digit is also called a nibble. The following figure shows a -digit headecimal number. Note that the positional representation with powers of 6 let us obtain the decimal value (integer positive) of the headecimal number. This is the same as converting a headecimal number into a decimal number. MATHEMATICAL REPRESENTATION -headecimal digits Second Digit Note that when we use the letters A-F in the multiplications inside the powers of 6 representation (e.g., A 6 +7 6 ), we need to replace the headecimal smbol b its decimal value. A =, B =, C =, D =, E = 4, F = 5 For eample: A 6 () 6. EXERCISE: Convert the following headecimal numbers (positive integers) to their decimal values: -he. digit representation h 6 +h 6 Decimal Number AB CE 5 7 F E9 h h 4 5 6 7 8 9 A B C D E F 4 5 6 7 8 9 4 5 First Digit He. number h h 5A 8 FB E A7 Powers of 6: h 6 + h 6 5 6 + A 6 6 + 6 6 + 8 6 F 6 + B 6 6 + E 6 A 6 + 7 6 Decimal Value 9 6 8 5 6 67 General case: Positional number representation for a headecimal number with n nibbles (headecimal digits): Most significant (leftmost) nibble h n- h n-... h h Least significant (rightmost) nibble
ECE-8L: Computer Logic Design Fall To convert a headecimal number into a decimal, we appl the following formula: Decimal Value (integer positive): D = h n- 6 n- + h n- 6 n- +... + h 6 + h 6 To avoid confusion, it is sometimes customar to append the prefi to a headecimal number: Eamples: FDA9: FDA9 F 6 5 + D 6 4 + 6 + A 6 + 9 6 + 6 B87C: B87C 6 5 + B 6 4 + 8 6 + 7 6 + 6 + C 6 The table presents the maimum attainable value for the given number of nibbles (headecimal digits). What pattern do ou find? Can ou complete it for the highlighted cases (4 and 6)? Number of bits Maimum value Range F 6 - F 6 - FF 6 - FF 6 - FFF 6 - FFF 6-4 5 FFFFF 6 5-6 5-6 h n- h n-...h h n FFF FFF 6 n - FFF FFF 6 n - Maimum value for n nibbles: The maimum decimal value with n nibbles is given b: D = FFF...FFF = F 6 n- + F 6 n- +... + F 6 + F 6 5 6 n- + 5 6 n- +... + 5 6 + 5 6 = 6 n - n nibbles With n nibbles, we can represent positive integer numbers from to 6 n -. (6 n numbers) Btes, KB (Kilobtes), MB (Megabtes), GB (Gigabtes), TB (Terabtes) Nibble Bte KB MB GB TB 4 bits 8 bits btes 6 btes 9 btes btes Note that the nibble (4 bits) is one headecimal digit. Also, one bte (8 bits) is represented b two headecimal digits. RELATIONSHIP BETWEEN HEXADECIMAL AND BINARY NUMBERS Conversions between headecimal and binar sstems are ver common when dealing with digital computers. In this activit, we will learn how these sstems are related and how eas it is to convert between one and the other. Headecimal to binar: We alread know how to convert a headecimal number into a decimal number. We can then can convert the decimal number into a binar number (using successive divisions). Binar to headecimal: We can first convert the binar number to a decimal number. Then, using an algorithm similar to the one that converts decimals into binar, we can convert our decimal number into a headecimal number.
ECE-8L: Computer Logic Design Fall SIMPLE METHOD TO CONVERT HEXADECIMAL TO BINARY NUMBERS AND VICEVERSA The previous two conversion processes are too tedious. Fortunatel, headecimal numbers have an interesting propert that allows quick conversion of binar numbers to headecimals and viceversa. Binar to headecimal: We group the binar numbers in groups of 4 (starting from the rightmost bit). If the last group of bits does not have four bits, we complete with eros to the left. Then, we independentl convert each group of 4 bits to its decimal value. Notice that 4 bits can onl take decimal values between and 4 - to 5, hence 4 bits represent onl one headecimal digit. In other words, for each group of 4 bits, there are onl 6 possible headecimal digits to pick from. The figure below shows an eample. Binar: decimal: headecimal: Then: Verification: = 5D 5 5 D = 6 + 4 + + + = 9 5D = 5 6 + D 6 = 9 binar dec he 4 4 5 5 6 6 7 7 8 8 9 9 A B C D 4 E 5 F Eercise: Group the following binar numbers in groups of 4 bits and obtain the headecimal representation. Use the table in the previous figure to pick the correspondent headecimal digit for each group of 4 bits. Binar number Headecimal number Headecimal to binar: It is basicall the inverse of the process of converting a binar into a headecimal numbers. We pick each headecimal digit and convert it (using alwas 4 bits) to its 4- bit binar representation. The binar number is the concatenation of all resulting group of 4 bits. C = C = DO NOT discard these eros when concatening!
ECE-8L: Computer Logic Design Fall Eercise: Convert these headecimal numbers to binar. Verif it b converting both the binar and headecimal number (the should match). Headecimal number A 89 4 A CE Binar number Decimal value The reason headecimal numbers are popular is because headecimal numbers provide a short-hand notation for binar numbers. Another common number sstem is computers is base-8 (octal). The conversion between base-8 and base- resembles that of converting between base-6 and base-. Here, we group the binar numbers in groups of bits: BINARY TO OCTAL Binar: octal: 5 Then: = 5 8 binar dec oct 4 4 5 5 6 6 7 7 Verification: = 6 + 4 + + + = 9 5 8 = 8 + 8 + 5 8 = 9 OCTAL TO BINARY 75 8 8 75 8 = 8 = DO NOT discard these eros when concatening!
ECE-8L: Computer Logic Design Fall INTRODUCTION TO FIXED-POINT ARITHMETIC We have been representing positive integer numbers. But what if we wanted to represent numbers with fractional parts? Fied-point arithmetic: Binar representation of positive decimal numbers with fractional parts. Given the following binar number: (b n b n b b. b b ) Formula to convert it to decimal: D = b n n + b n n + + b + b + b + b + Eample: (.) = + + + + + + To convert it to headecimal (or octal): Binar:.. octal: 5. 6 Binar:.. Now, what if we have a decimal number with fractional part? What we do is we divide the integer part and the fractional part. We obtain the binar representation of the integer part using what we know. As for the fractional part, what we do is successive multiplications b, the integer parts resulting are the results. Eample: headecimal: 5. A 8 base.65 MSB.65 =.5 = +.5 base???? base.7 MSB.7 =.4 = +.4 base????.5 =.5 = +.5.5 = = +.4 =.8 = +.8.8 =.6 = +.6. stop here!.6 =. = +.. =.4 = +.4.4 =.8 = +.8....
ECE-8L: Computer Logic Design Fall BINARY CODES: We know that with n bits, we can represent n numbers, from to n. However, with n bits, we can also represent n numbers in an range. Moreover, with n bits we can represent n different smbols. Eample: 7-bit US-ASCII character-encoding scheme. Each character is represented b 7 bits. Thus, the number of characters that can be represented is given b 7 = 8.Each character is said to have a binar code. Eample: 4-bit color. Each color is represented b 4 bits, providing 4 distinct color. Each color is said to have a binar code. In general, we might have N smbols to represent. In this case, the number of bits needed to represent N smbols is given b log N. Eample: N = 5 smbols. With bits, onl 4 smbols can be represented. With bits, 8 smbols can be represented. Thus, the number of bits required is n = = log 5 = log 8. Note that 8 is the power of closest to N=5 and that is greater than or equal to 5. Eample: Unicode can represent more than, characters and attempts to cover all world s scripts. A common character encoding is UTF-6, which uses two pairs of 6-bit units. For most purposes, a 6- bit unit suffices (covering 6 = 6556) characters. : C : A9
EMITTER RECEPTOR DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, THE UNIVERSITY OF NEW MEXICO ECE-8L: Computer Logic Design Fall BCD CODE: Here, we represent decimal numbers b independentl encoding each digit in binar form. Each digit requires 4 bits. Notice that the binar numbers ( ) to (5) are not used. Onl out of 6 values are used to encode ever decimal digit. This is a ver useful code for inputting devices (e.g. kepad). However, for implementing arithmetic operations, the binar number representation is more efficient. Also note that 6 values are wasted. The BCD code is not the same as the binar number!!! Eample: 58 This decimal number can be represented as a binar number: Using the BCD code, the binar representation would be: BCD decimal # 4 5 6 7 8 9 There eist man other binar codes (e.g., reflective gra code, 6--- code, -out-of-5 code) to represent decimal numbers. Usuall, each of them is tailored to an specific application. REFLECTIVE GRAY CODE: g g Decimal Number b b b How to convert from RGC to binar and binar to RGC? 4 5 6 7 g g g g g g g Application Measuring angular position with 4-bit RGC. 4 beams are emitted along an ais. When a light beam passes (transparent spots, represented as whites), we get a logical, otherwise. The RGC encoding makes that between areas onl one bit changes, thereb reducing the possibilit of a bad reading (especiall when the beam between adjacent areas. Eample: From to : Onl one bit flips. If we used to, two bits would flip. This is prone to more errors, especiall when the beams are close to the line where the two areas meet. 5 57.5 8.5.5 5 9 47.5 7 67.5 45 9.5.5 7.5 5 4 Angle -.5.5-45 45-67.5 67.5-9 9 -.5.5-5 5-57.5 57.5-8 8 -.5.5-5 5-47.5 47.5-7 7-9.5 9.5-5 5-7.5 7.5-6 g g g g
ECE-8L: Computer Logic Design Fall PRACTICE EXERCISES. Convert the following binar numbers to i) decimal, ii) octal, and iii) headecimal.... Represent the following decimal numbers in the binar sstem: 4,5,5,,,64,8,, 9,.5,.47,.. What is the minimum number of bits required to represent the following decimal numbers: 7, 56, 4, 6, 7, 49, 5,.65, 55.5,.5 4. We want to represent, different colors. What is the minimum number of bits required to represent those colors? 5. Represent the following decimal numbers in i) binar, ii) BCD, iii) and Reflective Gra Code 5 8 56 44 7 4 6. Convert the following binar numbers into its correspondent Reflective Gra Code representation. 7. Convert the following binar strings coded with Reflective Gra Code into the binar number sstem: 8. We have numpads. To open a lock, one must press the correct number on each one (e.g. 9 and ). BCD encoding is ver useful here, because each decimal number is represented with 4 bits and we can quickl create a circuit that opens the lock. If we wanted to use the binar representation of the decimal with digits, we would need to read the 8 lines, convert those 8 bits to the binar representation (a non-trivial task) and then perform the comparison.?
ECE-8L: Computer Logic Design Fall KARNAUGH MAPS: variables: f m m m m m m m m f f = ' + ' = m +m f f = ' + variables: f m m m m m 4 m 5 m 6 m 7 m m m 6 m 4 m m m 7 m 5 f f = '' + '' + f = ' + ' f = ' + '
ECE-8L: Computer Logic Design Fall 4 variables: w f m m m m m 4 m 5 m 6 m 7 m 8 m 9 m m m m m 4 m 5 w m m 4 m m 5 m m 7 m m 6 m m m 5 m 4 m 8 m 9 m m w w w w w w w w f = 'w' + w w w w w w w w w f w w w w w w w w f = ''w' + 'w + ''w w f = ' + w' w w w w w w w
sign and magnitude 's complement 's complement DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, THE UNIVERSITY OF NEW MEXICO ECE-8L: Computer Logic Design Fall REPRESENTATION OF SIGNED NUMBERS: Signed number: MSB alwas represents the sign. : negative, : positive. Representations: Sign-and-magnitude, 's complement, 's complement 's COMPLEMENT: For a number B = b n b b, the 's complement of B is given b a number K = k n k k. K represents '-B'. where K = ( n ) B, n = # of bits (including sign bit) ( n ): largest unsigned number with n bits. n n n k i i = ( n ) b i i (k i b i ) i = n k i + b i =, i k i = b i i= i= i= Eample: B = = 9 (positive number in 's complement) To get '-9' in 's complement representation, we just invert each bit of B: K = = 9 (negative number is 's complement) * Notice that K = ( n ) B is valid onl when we think of K and B as unsigned numbers. K = = = ( 5 ) 9 Eample: B = (negative number in 's complement) Remember: If the MSB is '', the number is negative. What number does it represent? We get the positive number first. K = = 5 Thus, B = -5. The 's complement representation allows us to represent both positive and negative numbers. Note that to obtain the 's complement of a number, ou need to invert the bits. Also, the 's complement of a number can be either a positive or negative number. With n bits, we can represent n numbers from n + to n. When using the 's complement representation, it is mandator to specif how man bits we are using. 's COMPLEMENT: For a number B = b n b b, the 's complement of B is given b a number K = k n k k. K represents '-B'. where K = n B, n = # of bits (including sign bit) K = n B = ( n ) B + b b b b 4 5 6 7 - - - -4-5 -6-7 4 5 6 7-7 -6-5 -4 - - - 4 5 6 7-8 -7-6 -5-4 - - - Then, to get the 's complement: first get the 's complement and then add. Or in other words, first invert all the bits and then add. Eample: B = = 9 (positive number in 's complement) To get '-9' in 's complement representation, we invert each bit of B and add : K = = 9 (negative number is 's complement) * K = n B is valid onl if we think of K and B as unsigned numbers. K = = = 5 9
ECE-8L: Computer Logic Design Fall Eample: B = (negative number in 's complement) Remember: If the MSB is '', the number is negative. What number does it represent? We get the positive number first. K = = 6 Thus, B = -6. With n bits, we can represent n numbers from n to n. When using the 's complement representation, it is mandator to specif how man bits we are using Formula to get the decimal value of a number in 's complement representation: If the number B is positive, we know that the MSB is, b n =. n B = b i i = b n n + b i i = b i i i= n i= n i= If the number B is negative, we know that the MSB is, b n =. If we take the 's complement of B, we get K. The number K represents -B. The number K is positive. K = n B is valid if we think of K and B as unsigned numbers: n k i i = n b i i i= n i= We want a formula that involves b i and that provides the decimal number -K. n (a) K = k i i = b i i n = b n n + b i i n i= n i= n n K = b n n + b i i n = n (b n ) + b i i i= n i= i= n n B = K = n ( ) + b i i = n + b i i (b) Using (a) and (b), the formula for the decimal value of B (either positive or negative) is: Eamples: = 4 + + = = 4 + = 8 B = b n n + b i i Sign-etension in 's complement representation: In man circumstances, we might want to represent numbers in 's complement with a fied number of bits. For eample, the following two numbers require a minimum of 5 bits: = 4 + + + = 9 = + + + = +5 What if we wanted to use 8 bits to represent them? The 's complement representation allows us to signetend: If the number is positive, we attach eros to the left. If the number is negative, we attach ones to the left. In the eample, note how we added three bits to the left in each case: = 4 + + + = 9 = + + + = +5 n i= i= i=
ECE-8L: Computer Logic Design Fall ARITHMETIC OPERATIONS UNSIGNED NUMBERS - ADDITION Addition of bits: + + + + + c s carr sum c s s c HA s c Addition of 5 bits: 5: + : 5: c o 4 + 4 s 4 s s s s c o c i + s c i s c o carr sum HA s c s c o There are inputs. Building the truth table is not practical! Instead we build a cascade of Full Adders. General case: 'n' bits: n- n- c out c n c n- c c c c c... in = s n- s s s Full adder design: c i i i c i+ s i i i c i i i c i s i = i i c i + i i c i + i i c i + i i c i s i s i = ( i i )c i + ( i i )c i = i i c i c i+ = i i + i c i + i c i
ECE-8L: Computer Logic Design Fall Overflow: Suppose we have onl 4 bits to represent binar numbers: + + cout= cout= OVERFLOW!!! Overflow occurs when an arithmetic operation require more bits than the bits we are using to represent our numbers. For 4 bits, the range is to 5. If the summation is greater than 5, then there is overflow. For n bits, overflow occurs when the summation is greater than n. To detect overflow: For unsigned numbers, the overflow bit is the same as the output cout. To avoid overflow when adding, a common technique is to sign-etend the two summands. For eample, if the two summands are 4-bits wide, then we add one more bit. So, we use 5 bits to represent our numbers. In the case of unsigned numbers, sign-etend amounts to ero-etend. Note that in general, if the two summands are n-bits wide, the result will have at most n+ bits. cout= + SIGNED NUMBERS ('s COMPLEMENT) - ADDITION +5 = + + = -5 = + + = +5 = + - = -5 = + - = +7 = cout= - = cout= + = -7 = cout= cout= There is no overflow here, we just ignore the cout bit We can use the same circuitr that we used for unsigned numbers. That's the great advantage of the 's complement representation. c out c 4 c c c c c in = s s Overflow: For 4 bits, the range that we represent is to. Overflow occurs when the summation falls outside this range. s s cout = c 4 +7 = + + = -7 = + + = +7 = + - = -7 = + - = +9 = -5 = +5 = -9 = c 4 =, c = c 4 =, c = c 4 =, c = c 4 =, c = If c 4 c, there is overflow. If c 4 = c, No overflow and we ignore c 4. Overflow = c 4 c
ECE-8L: Computer Logic Design Fall For n bits, the range is n to n. Overflow occurs when the summation falls outside this range. Overflow = c n c n Circuit for n =4: overflow c out c 4 c c c c c in = To avoid overflow when adding, a common technique is to sign-etend the two summands. For eample, if the two summands are 4-bits wide, then we add one more bit. So, we use 5 bits to represent our numbers. Note that in general, if the two summands are n-bits wide, the result will have at most n+ bits. Important: If there is no overflow, ou MUST discard the carr out, and onl use the 'n' bits. s s s cout = c 5 +7 = + -7 = + + = - = +9 = c 5 =, c 4 = s -9 = c 5 =, c 4 = SUBTRACTION: X - Y = X + (-Y). In this case, we onl need to create the 's complement of Y (the subtrahend). The circuit is basicall the same as the adder. We just need to include a circuit that creates the 's complement of Y: 7 - = 7 + (-): += -> -= cout = c 4 +7 = + - = +4 = c 4 =, c = overflow c out c 4 c c c c c in = s s s Adder/Subtractor Unit for 's complement numbers: s add/sub add = sub = overflow c out c 4 c c c c c in s s s s add/sub i f add/sub i f
ECE-8L: Computer Logic Design Fall PRACTICE EXERCISES. Complete the following table. Use the fewest number of bits for ever case. Decimal Sign-and-magnitude 's complement 's complement -9 56 78-67 -4 6-9 -888 44. Perform the following operations in 's complement. Use the fewest number of bits for the operation, sign-etend when needed. 45 + 5 7 + - 9-6 - 97 - - -98 +. Convert the following numbers to its 's complement representation. But ou need to use 6 bits to represent each number. - 98 5 97-8 789 4. We want to perform the following addition/subtraction operations. We are using the 's complement representation. However, we are restricted to use onl bits. Determine whether there is overflow when performing these operations onl using the decimal numbers. -5-4 + 9 + 5-5 - 7 - - 95 9 + 5. We want to perform the following operation using the 's complement representation. First, determine the number of bits that we require to represent the two summands. Then determine whether there is overflow b performing the operation in 's complement. Get c n, c n- (carries) on each case. +45 -+46-9+8-7- 49 + 5 99+ 6. The following is the formula to get the decimal value that a number in 's complement represents. B = b n n + b i i i= Derive a formula to get the decimal value that a number in 's complement represents. n