In: Computer Science
Determine for 5-bits system, if there is any overflow or carry
produced from the addition of following decimal numbers: [4*5 = 20
Marks]
a. -9 and -10
b. -14 and 14
c. 12 and -13
d. 9 and 12
Ans 1. -9 and -10
In the above problem we have two signed numbers -9 and -10.
As we know to add two signed numbers in binary we have to take 2's complement of negative numbers.
Note: 2's Complement is done by first complimenting true binary digit and then adding +1 to it. eg. -9 is 11001 where MSB is a signed digit (0 for positive and 1 for negative numbers). First complement of 1001 is 0110 and then by adding +1, 2's complement is 0111.
Decimal Sign digit Binary form 2's Complement
-9 1 1001 0111
-10 1 1010 0110
On adding 2's complement of -9 and -10, we get
-9 = 1 0111
-10 = 1 0110
___________
101101
Now, MSB is 1 denoting negative and 01101 is in 2's complement form. When we retake 2's complement form, we get 10011 that is 19 in decimal and hence the final output is -19 in decimal.
Note: The result is having an additional bit because in binary we need 5 bits required to represent 19 whereas 9 and 10 requires only 4 bits.
Ans 2. -14 and 14
In the above problem we have two equal and opposite numbers.
Decimal Sign digit Binary form 2's Complement
-14 1 1110 0010
14 0 1110 NA
On adding 2's complement of -14 and 14, we get
-14 = 1 0010
14 = 0 1110
___________
1 0 0000
The extra 1 gets discarded/removed and the final result is 00000.
Ans 3. 12 and -13
In the above problem we have one positive and one larger negative number.
Decimal Sign digit Binary form 2's Complement
12 0 1100 NA
-13 1 1101 0011
On adding 2's complement of 12 and -13, we get
12 = 0 1100
-13 = 1 0011
___________
1 1111
The final sum is represented in complemented form and on retaking 2's complement we get 0001 and MSB 1 shows negative numbers. Hence the final result is -1 in decimal.
Ans 4. 9 and 12
In the above problem we have both positive numbers or unsigned numbers.
Decimal Sign digit Binary form 2's Complement
9 0 1001 NA
12 0 1100 NA
On adding 2's complement of 12 and -13, we get
9 = 0 1001
12 = 0 1100
___________
010101
The final sum is 10101 that is 21 and MSB is 0 means positive number.
Note: The extra bit is because 21 requires 5 bits whereas 9 and 12 requires only 4 bits.