In: Computer Science
Problem: Perform following operations in binary using 8-bit
addition/subtraction/multiplication.
1. −80 + 42
2. −99 − 20
3. 60 − 70
4. −59 × 3
5. 52×−1
I am providing Solution using 2's complement.
2's Complement of a binary number is " Adding 1 to 1's compliment of that number" and, 1's complement of a binary no. obtained by converting digits 0 to 1 and 1 to 0.
ADDITION / SUBTRACTION
1.)
80 in binary is = 01010000 and 42 is = 00101010
-80 = (1's compliment of 80 )+ 1
So, -80= (10101111) +1 = 10110000
now, -80 + 42 = (10110000) + (00101010) = 11011010
Here 8th bit of Sum is 1 so, number is negative.
So, to find the magnitude of no, we have to find its 2’s complement.
So, 2’s complement of 11011010= 00100101 +1 = 00100110 = 38
and though, number is negative, hence, answer is -38
2.)
99= 01100011
-99= 10011100 + 1= 10011101
20= 00010100
-20= 11101011 + 1= 11101100
So, -99 + -20 = (10011101) + (11101100) = 10001001
Here 8th bit of Sum is 1 so, number is negative.
So, to find the magnitude of no, we have to find its 2’s complement.
So, 2’s complement of 10001001= 01110110 +1 = 01110111= 119
and though, number is negative, hence, answer is -119
3.)
60= 00111100
70= 01000110
-70= 10111001+ 1= 10111010
So, 60+ (-70) = (00111100) + (10111010) = 11110110
Here 8th bit of Sum is 1 so, number is negative.
So, to find the magnitude of no, we have to find its 2’s complement.
So, 2’s complement of 11110110= 00001001 +1 = 00001010= 10
and though, number is negative, hence, answer is -10
MULTIPLICATION
5.)
52= 00110100
1= 00000001
-1= 11111110+ 1=11111111
doing normal binary multiplication of (00110100) and (11111111)
So, Output is 11001100
Here 8th bit of Sum is 1 so, number is negative.
So, to find the magnitude of no, we have to find its 2’s complement.
So, 2’s complement of 11001100= 00110011 +1 = 00110100= 52
and though, numberis negative, hence, answer is -52
I hope, this solution will help you. If You still have doubt about 2's compliment or addition/subtraction/multiplication, you can put your doubts in comment section. I would like to sort them out. THANK YOU!