In: Computer Science
1a. What is the largest negative number that you could represent with 7 bits using signed magnitude? Show your work.
1b. What is the largest positive number that you could represent with 7 bits using 2’s complement? Show your work.
1c. Add the following two binary numbers 10110111 + 1011 = :Show your work.
1d. Solve the following decimal notation equation using 8-bit binary numbers and 2’s complement notation: 69 - 7 = :Show your work
Solution:-
1a The range of integers in sign magnitude form is:- - (2 ^(n-1) -1) to + (2^(n-1) -1)
Therefore the largest negative number that can be represented in sign magnitude with 7 bits is :-
Take n = 7, therefore - (2^(7-1)-1) = - ( 64-1) = -63.
1b. The range of integers in sign magnitude form is:- - (2 ^(n-1) ) to + (2^(n-1) -1)
Therefore take n = 7.
So largest positive integer that can be represented in 2's complement using 7 bits is = + (2^(7-1) -1 ) = 63.
1c. To add the 2 binary bits, we must know the following:-
a. 1 + 0 = 1 with carry 0
b. 0 + 0 = 0 with carry 0
c. 0 + 1 = 1 with carry 0
d. 1 + 1 =0 with carry forward as 1.
e. 1 + 1 + 1 = 1 with carry as 1
f. 1 + 1 + 0 = 0 with carry as 1.
Our binary numbers are:- A= 10110111 and B= 1011.
Here number B is of lesser length than A. Therefore we append 0's in front of B to make it of equal length as of A. Appending 0's will not cause any effect on the number.
updated numbers are :- A= 10110111 and B = 00001011
Now when we add the 2 binary numbers, we start addition of each bit pair from right to left by traversing.
For example- Take last bits of each of A and B which are 1 and 1. Therefore 1 + 1 = 0 with carry=1.
So this carry will be forward towards one distance left side.
ADDITION:-
A = 1 0 1 1 0 1 1 1
B = 0 0 0 0 1 0 1 1
_________________
C = 1 1 0 0 0 0 1 0 - Result/Sum
1d. We are given a substraction of 69 - 7 and we have to show it in binary substraction and use 2's complement notation in it.
Lets convert 69 into the binary format of 8 bits.
Idea - divide 69 by 2 and you will get a remainder, save it. Then divide the quotient we got while dividng 69 by 2, by 2 and save the remainder and repeat this until we are not able to divide.
Therefore binary representation of 69 = 0 1 0 0 0 1 0 1 (8bits)
Binary representation of 7 = 0 0 0 0 0 1 1 1 (8 bits).
Now we have to subtract 7 from 69 in binary.
Therefore we know that :- X - Y = X + (-Y)
Therefore we have to find the 2's complement of 7 which is = 1's complement of binary 7 + 1
Now 1's complement of binary 7 is = invert each of the bits of binary 7, therefore 1's complement of binary 7 is= 1 1 1 1 1 0 0 0
Lets now add binary representation of 69 and 2's complement of binary 7.
Therefore , using the previous addition concept we discussed above,
69 - 7 = 0 1 0 0 0 1 0 1 + 1 1 1 1 1 0 0 0
0 1 0 0 0 1 0 1
1 1 1 1 1 0 0 0
_____________
0 0 1 1 1 1 0 1 (leftmost carry will be discarded). -Result.
_______________________________________________________________________________________
Please rate the solution if it is helpful to you.
All the best.