Question

In: Computer Science

Perform the following calculations using 2s complement arithmetic. Indicate overflow where applicable. a. 14 + 2...

Perform the following calculations using 2s complement arithmetic. Indicate overflow where applicable.

a. 14 + 2 using 5 bits precision
b. 14 - 6 using 6 bits precision
c. 62 + 2 using 6 bits precision
d. -15 - 10 using 8 bits precision
e. 125 + 2 using 8 bits precision

Solutions

Expert Solution

a)
Number: 14
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 14 successively by 2 until the quotient is 0
   > 14/2 = 7, remainder is 0
   > 7/2 = 3, remainder is 1
   > 3/2 = 1, remainder is 1
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1110
So, 14 of decimal is 1110 in binary
Adding 1 zeros on left hand side of this number to make this of length 5
so, 14 in 2's complement binary is 01110

Number: 2
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 2 successively by 2 until the quotient is 0
   > 2/2 = 1, remainder is 0
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 10
So, 2 of decimal is 10 in binary
Adding 3 zeros on left hand side of this number to make this of length 5
so, 2 in 2's complement binary is 00010

Adding 01110 and 00010 in binary
    01110
    00010
----------
 (0)10000
----------
Sum does not produces a carry
So, sum of these numbers in binary is 10000

Verification:
---------------
sum = 10000
since left most bit is 1, this number is negative number.
so, follow these steps below to convert this into a decimal value.
I. first flip all the bits. Flip all 0's to 1 and all 1's to 0.
   10000 is flipped to 01111
II. Add 1 to above result
01111 + 1 = 10000
III. Now convert this result to decimal value
=> 10000
=> 1x2^4+0x2^3+0x2^2+0x2^1+0x2^0
=> 1x16+0x8+0x4+0x2+0x1
=> 16+0+0+0+0
=> 16
Answer: -16
14+2 must be 16
This is not correct since we can verify that 14+2 not equals -16
So, there was an overflow.

b)
Number: 14
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 14 successively by 2 until the quotient is 0
   > 14/2 = 7, remainder is 0
   > 7/2 = 3, remainder is 1
   > 3/2 = 1, remainder is 1
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1110
So, 14 of decimal is 1110 in binary
Adding 2 zeros on left hand side of this number to make this of length 6
so, 14 in 2's complement binary is 001110

Number: -6
Let's convert this to two's complement binary
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 6 successively by 2 until the quotient is 0
   > 6/2 = 3, remainder is 0
   > 3/2 = 1, remainder is 1
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 110
So, 6 of decimal is 110 in binary
Adding 3 zeros on left hand side of this number to make this of length 6
So, 6 in normal binary is 000110
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   000110 is flipped to 111001
Step 3:. Add 1 to above result
111001 + 1 = 111010
so, -6 in 2's complement binary is 111010

Adding 001110 and 111010 in binary
    001110
    111010
-----------
 (1)001000
-----------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 001000

Verification:
---------------
sum = 001000
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=> 1000
=> 1x2^3+0x2^2+0x2^1+0x2^0
=> 1x8+0x4+0x2+0x1
=> 8+0+0+0
=> 8
Answer: 8
This is correct since we can verify that 14+-6 = 8
So, there was no overflow.

c)
Number: 62
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 62 successively by 2 until the quotient is 0
   > 62/2 = 31, remainder is 0
   > 31/2 = 15, remainder is 1
   > 15/2 = 7, remainder is 1
   > 7/2 = 3, remainder is 1
   > 3/2 = 1, remainder is 1
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 111110
So, 62 of decimal is 111110 in binary
so, 62 in 2's complement binary is 111110

Number: 2
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 2 successively by 2 until the quotient is 0
   > 2/2 = 1, remainder is 0
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 10
So, 2 of decimal is 10 in binary
Adding 4 zeros on left hand side of this number to make this of length 6
so, 2 in 2's complement binary is 000010

Adding 111110 and 000010 in binary
    111110
    000010
-----------
 (1)000000
-----------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 000000

Verification:
---------------
sum = 000000
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=> 
=> 
=> 
=> 
=> 0
Answer: 0
62+2 must be 64
This is not correct since we can verify that 62+2 not equals 0
So, there was an overflow.

d)
Number: -15
Let's convert this to two's complement binary
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 15 successively by 2 until the quotient is 0
   > 15/2 = 7, remainder is 1
   > 7/2 = 3, remainder is 1
   > 3/2 = 1, remainder is 1
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1111
So, 15 of decimal is 1111 in binary
Adding 4 zeros on left hand side of this number to make this of length 8
So, 15 in normal binary is 00001111
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00001111 is flipped to 11110000
Step 3:. Add 1 to above result
11110000 + 1 = 11110001
so, -15 in 2's complement binary is 11110001

Number: -10
Let's convert this to two's complement binary
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 10 successively by 2 until the quotient is 0
   > 10/2 = 5, remainder is 0
   > 5/2 = 2, remainder is 1
   > 2/2 = 1, remainder is 0
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1010
So, 10 of decimal is 1010 in binary
Adding 4 zeros on left hand side of this number to make this of length 8
So, 10 in normal binary is 00001010
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00001010 is flipped to 11110101
Step 3:. Add 1 to above result
11110101 + 1 = 11110110
so, -10 in 2's complement binary is 11110110

Adding 11110001 and 11110110 in binary
    11110001
    11110110
-------------
 (1)11100111
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 11100111

Verification:
---------------
sum = 11100111
since left most bit is 1, this number is negative number.
so, follow these steps below to convert this into a decimal value.
I. first flip all the bits. Flip all 0's to 1 and all 1's to 0.
   11100111 is flipped to 00011000
II. Add 1 to above result
00011000 + 1 = 00011001
III. Now convert this result to decimal value
=> 11001
=> 1x2^4+1x2^3+0x2^2+0x2^1+1x2^0
=> 1x16+1x8+0x4+0x2+1x1
=> 16+8+0+0+1
=> 25
Answer: -25
This is correct since we can verify that -15+-10 = -25
So, there was no overflow.

e)
Number: 125
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 125 successively by 2 until the quotient is 0
   > 125/2 = 62, remainder is 1
   > 62/2 = 31, remainder is 0
   > 31/2 = 15, remainder is 1
   > 15/2 = 7, remainder is 1
   > 7/2 = 3, remainder is 1
   > 3/2 = 1, remainder is 1
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1111101
So, 125 of decimal is 1111101 in binary
Adding 1 zeros on left hand side of this number to make this of length 8
so, 125 in 2's complement binary is 01111101

Number: 2
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 2 successively by 2 until the quotient is 0
   > 2/2 = 1, remainder is 0
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 10
So, 2 of decimal is 10 in binary
Adding 6 zeros on left hand side of this number to make this of length 8
so, 2 in 2's complement binary is 00000010

Adding 01111101 and 00000010 in binary
    01111101
    00000010
-------------
 (0)01111111
-------------
Sum does not produces a carry
So, sum of these numbers in binary is 01111111

Verification:
---------------
sum = 01111111
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=> 1111111
=> 1x2^6+1x2^5+1x2^4+1x2^3+1x2^2+1x2^1+1x2^0
=> 1x64+1x32+1x16+1x8+1x4+1x2+1x1
=> 64+32+16+8+4+2+1
=> 127
Answer: 127
This is correct since we can verify that 125+2 = 127
So, there was no overflow.




Related Solutions

using 8 bits and 2s complement integer arithmetic, show how a processor would calculate 63 -...
using 8 bits and 2s complement integer arithmetic, show how a processor would calculate 63 - 17
Question 1                   (Amounts are 14% VAT inclusive, where applicable. All calculations are...
Question 1                   (Amounts are 14% VAT inclusive, where applicable. All calculations are to be done to the nearest cent)                   Required                   Record the transactions in the correct subsidiary journals, post to the general                   ledger, debtors ledger and creditors ledger, and draw up a trial balance.                   On 1 January 2007, Pets Traders had the following balances:                   Stock R1...
Digital arithmetic: a) Convert +35 to 2-complement b) Convert -35 to 2-complement c) Convert 2-complement from...
Digital arithmetic: a) Convert +35 to 2-complement b) Convert -35 to 2-complement c) Convert 2-complement from 1101 1101 to decimal d) Add 35 - 35 in binary
4.4-4.6 The term arithmetic overflow refers to the condition where the result of some computation is...
4.4-4.6 The term arithmetic overflow refers to the condition where the result of some computation is outside the range of expected results. When a computation produces a result with absolute value smaller then the computer can represent we have arithmetic underflow. Answer the following 4 point questions regarding the detection of incorrect computations when processing ALU instructions. 4.4 We have explored the potential for incorrect answers caused by overflow when the ALU operates on integers. For completeness, we need to...
Problem 5: Perform the subtraction on the following pairs of signed numbers using the 2’s complement...
Problem 5: Perform the subtraction on the following pairs of signed numbers using the 2’s complement system. Express the results as signed binary numbers and as decimal values. Please show all work to fully understand. A. 01001 - 11010 B. 10010 - 10011
Perform the following calculation in a 6-bit two’s complement system. Show your work. Indicate at the...
Perform the following calculation in a 6-bit two’s complement system. Show your work. Indicate at the end if there will be overflow/underflow or not and why. 1810 – 1010
convert +38 and +17 to binary using the signed 2s complement representation and enough digits to...
convert +38 and +17 to binary using the signed 2s complement representation and enough digits to accomaodate the numbers. Then perform the binary equivalent of (-38) and +17
Assume that we are executing the following code on a 32-bit machine using two’s complement arithmetic...
Assume that we are executing the following code on a 32-bit machine using two’s complement arithmetic for signed integers. Which of the following will be printed when the following code is executed (circle those printed, and show work; e.g., how the values are stored): #include <stdio.h> int main() { char x = 0xF;                // x = ________ char y = -1;                 // y = ________ unsigned char z = 0xFF;      // z = 11111111        if (x<z)     printf("performed unsigned compare,...
add the following numbers using 16-bit 2's complement. show all the steps and calculations. Please also...
add the following numbers using 16-bit 2's complement. show all the steps and calculations. Please also show steps to verify that the answer is correct. -7493 and -6372
add the following numbers using 16-bit 2's complement. show all the steps and calculations. Please also...
add the following numbers using 16-bit 2's complement. show all the steps and calculations. Please also show steps to verify that the answer is correct. 2368 and -772
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT