CS/EE2 INTRODUCTION TO COMPUTER ENGINEERING SPRING 23 DUE : February 22, 23 HOMEWORK I READ : Related portions of the following chapters : È Chapter È Chapter 2 È Appendix E ASSIGNMENT : There are eight questions from the textbook Solve all homework and exam problems as shown in class and sample solutions ) Solve Problem.8. 2) Solve Problem 2.6. 3) Solve Problem 2. (b). 4) Solve Problem 2.2. 5) Solve Problem 2.4 (a) and (e). Assume that the numbers are 2 s Complement numbers. Indicate if there is an overflow. 6) Solve Problem 2.8 (b). 7) Solve Problem 2.2 (c). 8) Solve Problem 2.46 (e). Polytechnic Institute of NYU Page of 8 Handout No : 2 February, 23
RELEVANT QUESTIONS AND ANSWERS Q) Hex digits are used to represent two numbers that are 6-bit 2 s complement numbers : 4AF8 - B5E = ( ) Perform the subtraction operation, by converting it to a 6-bit addition operation. Show the result in decimal. A) First, we convert the digits to bit strings : by using 6 bits 4 A F 8 by using 6 bits B 5 E In order to convert the subtraction to an addition, we need to take the 2 s complement of the second number : 2 ( ) = ( ) We calculate the corresponding decimal number : 5 4 3 2 9 8 7 6 5 4 3 2 By numbering the bit positions from right to left, starting at, we convert the binary number to a decimal number : ==> 2 2 3 2 4 2 7 2 8 2 9 2 2 2 3 = 2 8 6 28 256 52 24 248 892 = (286) Observation : we added a negative number and a positive number, therefore, there cannot be any overflow. Q2) Perform the following operation in 2 s complement arithmetic : F6 49 = The numbers are shown in the Hexadecimal notation. Thus, first convert the numbers to binary, and then add them. Make observations on the addition. A2) Replace each hexadecimal digit with four bits to convert them to 2 s Complement numbers : Polytechnic Institute of NYU Page 2 of 8 CS/EE2 Handout No : 2 February, 23
F 6 F 6 4 9 4 9 (3 F) Hex 3 F There is no overflow, since the two numbers added have different sign bits : one is negative and the other is positive. Thus, the result cannot exceed the limits for 8-bit 2 s complement numbers : (-28) and (27). The bit is the carry out from the leftmost bit position and it is. Q3) Without using a calculator, perform the following addition in binary as shown in class : 2 s complement numbers Make observations on the addition. Finally, convert the result to decimal. A3) We are given the following addition : 2 s complement numbers Since it is the 2 s complement system and the second number is shorter than the first, we sign extend the second number so both numbers have eight bits. The sign bit of the second number is (it is negative), so we have to catenate s to the left of it : Now we have the following addition : Observation : we know that there cannot be any overflow since we added a positive number (the first number) and a negative number (the second number). We convert the result to decimal directly since the result is positive : 7 6 5 4 3 2 2 6 2 3 2 2 64 8 4 (76) the result Polytechnic Institute of NYU Page 3 of 8 CS/EE2 Handout No : 2 February, 23
Q4) Consider the following 8-bit addition on two 2 s Complement Binary numbers where the first number is shown in Hex coding : (A 5) Hex Hex coded Without using a calculator, perform the 8-bit 2 s Complement Binary addition as shown in class. Make observations on the overflow. Then, convert the result to a decimal number as shown in class. Note again that both numbers above are 2 s Complement Binary numbers and the first number is shown in Hex-coding. A4) Since the first number is Hex coded, first we replace its Hex coded digits with bits. Then, we perform the addition in the 2 s Complement Binary system : (A 5) Hex (A 5) Hex = A 5 c in We added two negative numbers and the result is negative. Thefore, there is no overflow. That is, the result is correct! We can convert the result to decimal. Since the result is negative, we have to make it positive first : 2 = 7 6 5 4 3 2 2 6 2 5 2 3 2 2 2 = 64 32 8 4 = (9) =>(-9) Q5) Consider the following subtraction on 2 s Complement numbers represented in Hex coding : 8 A 8 Without using a calculator, perform the 8-bit 2 s Complement Binary subtraction, by converting it to an 8-bit addition as shown in class. Make observations on the overflow. Then, convert the result to a decimal number as shown in class. Note again that both Hex-coded numbers above are 2 s Complement Binary numbers and so you will perform the subtraction via an addition. A5) Since the numbers are Hex coded, first we replace the Hex coded digits with bits. Then, before we convert the subtraction to an addition in the 2 s Complement Binary system, we perform a sign extension on the second number since it is shorter : Polytechnic Institute of NYU Page 4 of 8 CS/EE2 Handout No : 2 February, 23
8 A 8 A 8 8 c in We added two numbers with opposite signs. There cannot be an overflow. That is, the result is correct! We can convert the result to decimal. Since the result is negative, we have to make it positive first : 2 = 7 6 5 4 3 2 2 6 2 5 2 3 2 2 2 = 64 32 8 4 2 = () =>(-) Q6) Determine the base (radix) of the numbers used in the following addition : 3 6 = 2 A6) There are several ways to solve the problem. One that uses the general conversion formula is as follows : È First we have to see if 6 in the unknown radix is equal to 6 in decimal. By using the general conversion formula we see that : (6) r = (6) r = 6 * r = 6 * = (6) È Then, we do the addition by using the general conversion formula to obtain the unknown radix r : 3 6 2 ( 3) r (6) r = (2 ) r => ( * r ) (3 * r ) 6 = (2 * r ) ( * r ) => r 3 6 = 2r => r 9 = 2r => r = 8 Q7) Without using a calculator, perform the following 8-bit 2 s Complement Binary subtraction, by converting it to an 8-bit addition as shown in class : Polytechnic Institute of NYU Page 5 of 8 CS/EE2 Handout No : 2 February, 23
Make observations on the overflow. Then, convert the result to a decimal number and also code the result in Hexadecimal as shown in class. Note again that both numbers above are 2 s Complement Binary numbers and so you will perform the subtraction via an addition. A7) Before we convert the subtraction to an addition in the 2 s Complement Binary system, we perform a sign extension on the second number since it is shorter and both numbers are 2 s Complement numbers : c in We added two numbers with opposite signs. There cannot be an overflow. That is, the result is correct! We can convert the result to decimal. Since the result is negative, we have to make it positive first : 2 = 2 6 2 5 2 2 2 = 64 32 4 = () 7 6 5 4 3 2 =>(-) The result of the addition in terms of Hex digits : 9 B (9B) Hex Q8) Perform the following subtraction operation on the two 8-bit 2 s complement binary numbers below, by converting it to an 8-bit addition operation. Also, determine the missing bits and show the result in decimal : a b s - ( ) A8) (b) We need to take the 2 s complement of (b) to convert the subtraction to an addition first : 2 2 ( b ) = ( ) = = (-b) Polytechnic Institute of NYU Page 6 of 8 CS/EE2 Handout No : 2 February, 23
(-b) The sum is a negative number. We cannot convert it to decimal directly. We will convert the negative of the sum to decimal : 2 (-sum) = () = = 2 2 2 3 2 5 = 2832 = (43). The sum is (-43) Number b is also a negative number. We will convert its negative to decimal first : (-b) = => 2 2 2 2 3 2 4 = 4 8 6 = (29) => b = (-29) 7 6 5 4 3 2 Note that we added a negative number (a) and a positive number (-b), therefore, there cannot be any overflow. Q9) Consider the following addition on two 2 s Complement Binary numbers : Without using a calculator, perform the addition as shown in class. Make observations on the overflow. Then, convert the result to a decimal number as shown in class. Finally, show the result in Hexadecimal coding as done in class. Q9) We perform the addition as follows : We see that the second number has less number of bits. We perform a sign extension on the second number since we are adding 2 s Complement numbers We added two negative numbers and the result is negative. Thefore, there is no overflow. That is, the result is correct! We can convert the result to decimal. Since the result is negative, we have to make it positive first : Polytechnic Institute of NYU Page 7 of 8 CS/EE2 Handout No : 2 February, 23
2 = 2 5 2 3 2 2 2 = 32 8 4 2 = (46) 7 6 5 4 3 2 =>(-46) D 2 =>(D2) Hex Q) Consider the following subtraction on two 2 s Complement Binary numbers : - Without using a calculator, perform the 2 s Complement Binary subtraction, by converting it to an addition as shown in class. Make observations on the overflow. Then, convert the result to a decimal number as shown in class. Finally, show the result in Hexadecimal coding as done in class. A) We perform the addition as follows : - In order to convert the subtraction to an addition, we complement the second number and add c in We added two numbers with opposite signs Thefore, there cannot be an overflow That is, the result is correct! 7 6 5 4 3 2 2 5 2 2 = 32 2 = (35) 2 3 => (23) Hex Polytechnic Institute of NYU Page 8 of 8 CS/EE2 Handout No : 2 February, 23