In: Computer Science
Show ALL work if it is required for the question and BASES
4. Convert the following from Signed Binary to Decimal: (signed)
a. 10011010
b. 01001101
5. 10000001 - 01100110
6. 80D3 + 74C2
4)
a)
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.
10011010 is flipped to 01100101
II. Add 1 to above result
01100101 + 1 = 01100110
III. Now convert this result to decimal value
Converting 1100110 to decimal
1100110
=> 1x2^6+1x2^5+0x2^4+0x2^3+1x2^2+1x2^1+0x2^0
=> 1x64+1x32+0x16+0x8+1x4+1x2+0x1
=> 64+32+0+0+4+2+0
=> 102
Answer: -102
b)
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 1001101 to decimal
1001101
=> 1x2^6+0x2^5+0x2^4+1x2^3+1x2^2+0x2^1+1x2^0
=> 1x64+0x32+0x16+1x8+1x4+0x2+1x1
=> 64+0+0+8+4+0+1
=> 77
Answer: 77
5)
convert -01100110 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
01100110 is flipped to 10011001
Step 2:. Add 1 to above result
10011001 + 1 = 10011010
Adding 10000001 and 10011010 in binary
10000001
10011010
-------------
(1)00011011
-------------
So, sum of these numbers in binary is 00011011
Verification
---------------
first = 10000001
Converting 10000001 to decimal
10000001
=> 1x2^7+0x2^6+0x2^5+0x2^4+0x2^3+0x2^2+0x2^1+1x2^0
=> 1x128+0x64+0x32+0x16+0x8+0x4+0x2+1x1
=> 128+0+0+0+0+0+0+1
=> 129
second = 10011010
Converting 10011010 to decimal
10011010
=> 1x2^7+0x2^6+0x2^5+1x2^4+1x2^3+0x2^2+1x2^1+0x2^0
=> 1x128+0x64+0x32+1x16+1x8+0x4+1x2+0x1
=> 128+0+0+16+8+0+2+0
=> 154
sum = 00011011
Converting 00011011 to decimal
00011011
=> 0x2^7+0x2^6+0x2^5+1x2^4+1x2^3+0x2^2+1x2^1+1x2^0
=> 0x128+0x64+0x32+1x16+1x8+0x4+1x2+1x1
=> 0+0+0+16+8+0+2+1
=> 27
129+154 must be 283
This is not correct since we can verify that 129+154 not equals 27
So, there was an overflow.
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 00011011
Verification
---------------
first = 10000001
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.
10000001 is flipped to 01111110
II. Add 1 to above result
01111110 + 1 = 01111111
III. Now convert this result to decimal value
Converting 1111111 to decimal
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
second = 10011010
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.
10011010 is flipped to 01100101
II. Add 1 to above result
01100101 + 1 = 01100110
III. Now convert this result to decimal value
Converting 1100110 to decimal
1100110
=> 1x2^6+1x2^5+0x2^4+0x2^3+1x2^2+1x2^1+0x2^0
=> 1x64+1x32+0x16+0x8+1x4+1x2+0x1
=> 64+32+0+0+4+2+0
=> 102
Answer: -102
sum = 00011011
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 11011 to decimal
11011
=> 1x2^4+1x2^3+0x2^2+1x2^1+1x2^0
=> 1x16+1x8+0x4+1x2+1x1
=> 16+8+0+2+1
=> 27
Answer: 27
-127+-102 must be -229
This is not correct since we can verify that -127+-102 not equals 27
So, there was an overflow.
6)
Hexadecimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
Use this table to convert from hexadecimal to binary
Converting 80D3 to binary
8 => 1000
0 => 0000
D => 1101
3 => 0011
So, in binary 80D3 is 1000000011010011
Converting 74C2 to binary
7 => 0111
4 => 0100
C => 1100
2 => 0010
So, in binary 74C2 is 0111010011000010
Adding 1000000011010011 and 0111010011000010 in binary
1000000011010011
0111010011000010
---------------------
(0)1111010110010101
---------------------
So, sum of these numbers in binary is 1111010110010101
Verification
---------------
first = 1000000011010011
Converting 1000000011010011 to decimal
1000000011010011
=> 1x2^15+0x2^14+0x2^13+0x2^12+0x2^11+0x2^10+0x2^9+0x2^8+1x2^7+1x2^6+0x2^5+1x2^4+0x2^3+0x2^2+1x2^1+1x2^0
=> 1x32768+0x16384+0x8192+0x4096+0x2048+0x1024+0x512+0x256+1x128+1x64+0x32+1x16+0x8+0x4+1x2+1x1
=> 32768+0+0+0+0+0+0+0+128+64+0+16+0+0+2+1
=> 32979
second = 0111010011000010
Converting 0111010011000010 to decimal
0111010011000010
=> 0x2^15+1x2^14+1x2^13+1x2^12+0x2^11+1x2^10+0x2^9+0x2^8+1x2^7+1x2^6+0x2^5+0x2^4+0x2^3+0x2^2+1x2^1+0x2^0
=> 0x32768+1x16384+1x8192+1x4096+0x2048+1x1024+0x512+0x256+1x128+1x64+0x32+0x16+0x8+0x4+1x2+0x1
=> 0+16384+8192+4096+0+1024+0+0+128+64+0+0+0+0+2+0
=> 29890
sum = 1111010110010101
Converting 1111010110010101 to decimal
1111010110010101
=> 1x2^15+1x2^14+1x2^13+1x2^12+0x2^11+1x2^10+0x2^9+1x2^8+1x2^7+0x2^6+0x2^5+1x2^4+0x2^3+1x2^2+0x2^1+1x2^0
=> 1x32768+1x16384+1x8192+1x4096+0x2048+1x1024+0x512+1x256+1x128+0x64+0x32+1x16+0x8+1x4+0x2+1x1
=> 32768+16384+8192+4096+0+1024+0+256+128+0+0+16+0+4+0+1
=> 62869
This is correct since we can verify that 32979+29890 = 62869
So, there was no overflow.
Sum does not produces a carry
So, sum of these numbers in binary is 1111010110010101
Verification
---------------
first = 1000000011010011
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.
1000000011010011 is flipped to 0111111100101100
II. Add 1 to above result
0111111100101100 + 1 = 0111111100101101
III. Now convert this result to decimal value
Converting 111111100101101 to decimal
111111100101101
=> 1x2^14+1x2^13+1x2^12+1x2^11+1x2^10+1x2^9+1x2^8+0x2^7+0x2^6+1x2^5+0x2^4+1x2^3+1x2^2+0x2^1+1x2^0
=> 1x16384+1x8192+1x4096+1x2048+1x1024+1x512+1x256+0x128+0x64+1x32+0x16+1x8+1x4+0x2+1x1
=> 16384+8192+4096+2048+1024+512+256+0+0+32+0+8+4+0+1
=> 32557
Answer: -32557
second = 0111010011000010
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 111010011000010 to decimal
111010011000010
=> 1x2^14+1x2^13+1x2^12+0x2^11+1x2^10+0x2^9+0x2^8+1x2^7+1x2^6+0x2^5+0x2^4+0x2^3+0x2^2+1x2^1+0x2^0
=> 1x16384+1x8192+1x4096+0x2048+1x1024+0x512+0x256+1x128+1x64+0x32+0x16+0x8+0x4+1x2+0x1
=> 16384+8192+4096+0+1024+0+0+128+64+0+0+0+0+2+0
=> 29890
Answer: 29890
sum = 1111010110010101
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.
1111010110010101 is flipped to 0000101001101010
II. Add 1 to above result
0000101001101010 + 1 = 0000101001101011
III. Now convert this result to decimal value
Converting 101001101011 to decimal
101001101011
=> 1x2^11+0x2^10+1x2^9+0x2^8+0x2^7+1x2^6+1x2^5+0x2^4+1x2^3+0x2^2+1x2^1+1x2^0
=> 1x2048+0x1024+1x512+0x256+0x128+1x64+1x32+0x16+1x8+0x4+1x2+1x1
=> 2048+0+512+0+0+64+32+0+8+0+2+1
=> 2667
Answer: -2667
This is correct since we can verify that -32557+29890 = -2667
So, there was no overflow.
Let's convert this sum(1111010110010101) back to hexadecimal
Converting 1111010110010101 to hexadecimal
1111 => F
0101 => 5
1001 => 9
0101 => 5
So, in hexadecimal 1111010110010101 is 0xF595
Answer: 0xF595