In: Computer Science
1. What is the two’s complement of: 00110101
2. Carry out the following calculation using 8-bit signed arithmetic (convert to 8-bit binary sequences) and use two’s complement for the negative number, give the result as both an 8-bit binary sequence and in base 10: 127 – 74.
3. What does shifting a binary sequence to left by 3 places correspond to (from the arithmetic standpoint)
1)
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 110101 to decimal
110101
=> 1x2^5+1x2^4+0x2^3+1x2^2+0x2^1+1x2^0
=> 1x32+1x16+0x8+1x4+0x2+1x1
=> 32+16+0+4+0+1
=> 53
Answer: 53
2)
Number: 127
Let's convert this to two's complement binary
127
Since this is a positive number. we can directly convert this into binary
Divide 127 successively by 2 until the quotient is 0
> 127/2 = 63, remainder is 1
> 63/2 = 31, remainder is 1
> 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 1111111
So, 127 of decimal is 1111111 in binary
so, 127 in 2's complement binary is 01111111
Number: -74
Let's convert this to two's complement binary
-74
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 74 successively by 2 until the quotient is 0
> 74/2 = 37, remainder is 0
> 37/2 = 18, remainder is 1
> 18/2 = 9, remainder is 0
> 9/2 = 4, remainder is 1
> 4/2 = 2, remainder is 0
> 2/2 = 1, remainder is 0
> 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1001010
So, 74 of decimal is 1001010 in binary
So, 74 in normal binary is 01001010
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
01001010 is flipped to 10110101
Step 3:. Add 1 to above result
10110101 + 1 = 10110110
so, -74 in 2's complement binary is 10110110
Adding 01111111 and 10110110 in binary
01111111
10110110
-------------
(1)00110101
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 00110101
Verification:
---------------
sum = 00110101
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 110101 to decimal
110101
=> 1x2^5+1x2^4+0x2^3+1x2^2+0x2^1+1x2^0
=> 1x32+1x16+0x8+1x4+0x2+1x1
=> 32+16+0+4+0+1
=> 53
Answer: 53
This is correct since we can verify that 127+-74 = 53
So, there was no overflow.
3)
by shifting binary sequence left by n bits, it multiplies the number by 2^n
by shifting by 3 bits, it multiples the number by 8.