In: Computer Science
Interpret these signed 8-bit sequences with each type of signed/unsigned encoding. Remember the bits are arbitrary! They can be interpreted in many different ways.
C.1: Complete the following table using decimal (base-10) numbers. The first line is already completed for you |
bit sequence | unsigned | sign-magnitude | 1s’ complement | 2’s complement |
00000101 | +5 | +5 | +5 | +5 |
11110001 | ? | ? | ? | ? |
01010011 | ? | ? | ? | ? |
10000000 | ? | ? | ? | ? |
11111111 | ? | ? | ? | ? |
a) 00000101
Unsigned:
Converting 00000101 to decimal
00000101
=> 0x2^7+0x2^6+0x2^5+0x2^4+0x2^3+1x2^2+0x2^1+1x2^0
=> 0x128+0x64+0x32+0x16+0x8+1x4+0x2+1x1
=> 0+0+0+0+0+4+0+1
=> 5
Answer: 5
sign-magnitude:
Left most bit is 0. so, it's positive.
Now, let's convert rest of the bits 0000101 to decimal
Converting 0000101 to decimal
0000101
=> 0x2^6+0x2^5+0x2^4+0x2^3+1x2^2+0x2^1+1x2^0
=> 0x64+0x32+0x16+0x8+1x4+0x2+1x1
=> 0+0+0+0+4+0+1
=> 5
so, 00000101 from sign-magnitude to decimal is 5
Answer: 5
1's complement:
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 101 to decimal
101
=> 1x2^2+0x2^1+1x2^0
=> 1x4+0x2+1x1
=> 4+0+1
=> 5
Answer: 5
2's complement:
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 101 to decimal
101
=> 1x2^2+0x2^1+1x2^0
=> 1x4+0x2+1x1
=> 4+0+1
=> 5
Answer: 5
b) 11110001
Unsigned:
Converting 11110001 to decimal
11110001
=> 1x2^7+1x2^6+1x2^5+1x2^4+0x2^3+0x2^2+0x2^1+1x2^0
=> 1x128+1x64+1x32+1x16+0x8+0x4+0x2+1x1
=> 128+64+32+16+0+0+0+1
=> 241
Answer: 241
sign-magnitude:
Left most bit is 1. so, it's negative.
Now, let's convert rest of the bits 1110001 to decimal
Converting 1110001 to decimal
1110001
=> 1x2^6+1x2^5+1x2^4+0x2^3+0x2^2+0x2^1+1x2^0
=> 1x64+1x32+1x16+0x8+0x4+0x2+1x1
=> 64+32+16+0+0+0+1
=> 113
so, 11110001 from sign-magnitude to decimal is -113
Answer: -113
1's complement:
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.
11110001 is flipped to 00001110
II. Now convert this result to decimal value
Converting 1110 to decimal
1110
=> 1x2^3+1x2^2+1x2^1+0x2^0
=> 1x8+1x4+1x2+0x1
=> 8+4+2+0
=> 14
Answer: -14
2's complement:
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.
11110001 is flipped to 00001110
II. Add 1 to above result
00001110 + 1 = 00001111
III. Now convert this result to decimal value
Converting 1111 to decimal
1111
=> 1x2^3+1x2^2+1x2^1+1x2^0
=> 1x8+1x4+1x2+1x1
=> 8+4+2+1
=> 15
Answer: -15
c) 01010011
Unsigned:
Converting 01010011 to decimal
01010011
=> 0x2^7+1x2^6+0x2^5+1x2^4+0x2^3+0x2^2+1x2^1+1x2^0
=> 0x128+1x64+0x32+1x16+0x8+0x4+1x2+1x1
=> 0+64+0+16+0+0+2+1
=> 83
Answer: 83
sign-magnitude:
Left most bit is 0. so, it's positive.
Now, let's convert rest of the bits 1010011 to decimal
Converting 1010011 to decimal
1010011
=> 1x2^6+0x2^5+1x2^4+0x2^3+0x2^2+1x2^1+1x2^0
=> 1x64+0x32+1x16+0x8+0x4+1x2+1x1
=> 64+0+16+0+0+2+1
=> 83
so, 01010011 from sign-magnitude to decimal is 83
Answer: 83
1's complement:
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 1010011 to decimal
1010011
=> 1x2^6+0x2^5+1x2^4+0x2^3+0x2^2+1x2^1+1x2^0
=> 1x64+0x32+1x16+0x8+0x4+1x2+1x1
=> 64+0+16+0+0+2+1
=> 83
Answer: 83
2's complement:
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 1010011 to decimal
1010011
=> 1x2^6+0x2^5+1x2^4+0x2^3+0x2^2+1x2^1+1x2^0
=> 1x64+0x32+1x16+0x8+0x4+1x2+1x1
=> 64+0+16+0+0+2+1
=> 83
Answer: 83
d) 10000000
Unsigned:
Converting 10000000 to decimal
10000000
=> 1x2^7+0x2^6+0x2^5+0x2^4+0x2^3+0x2^2+0x2^1+0x2^0
=> 1x128+0x64+0x32+0x16+0x8+0x4+0x2+0x1
=> 128+0+0+0+0+0+0+0
=> 128
Answer: 128
sign-magnitude:
Left most bit is 1. so, it's negative.
Now, let's convert rest of the bits 0000000 to decimal
Converting 0000000 to decimal
0000000
=> 0x2^6+0x2^5+0x2^4+0x2^3+0x2^2+0x2^1+0x2^0
=> 0x64+0x32+0x16+0x8+0x4+0x2+0x1
=> 0+0+0+0+0+0+0
=> 0
so, 10000000 from sign-magnitude to decimal is 0
Answer: 0
1's complement:
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.
10000000 is flipped to 01111111
II. 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
2's complement:
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.
10000000 is flipped to 01111111
II. Add 1 to above result
01111111 + 1 = 10000000
III. Now convert this result to decimal value
Converting 10000000 to decimal
10000000
=> 1x2^7+0x2^6+0x2^5+0x2^4+0x2^3+0x2^2+0x2^1+0x2^0
=> 1x128+0x64+0x32+0x16+0x8+0x4+0x2+0x1
=> 128+0+0+0+0+0+0+0
=> 128
Answer: -128
e) 11111111
Unsigned:
Converting 11111111 to decimal
11111111
=> 1x2^7+1x2^6+1x2^5+1x2^4+1x2^3+1x2^2+1x2^1+1x2^0
=> 1x128+1x64+1x32+1x16+1x8+1x4+1x2+1x1
=> 128+64+32+16+8+4+2+1
=> 255
Answer: 255
sign-magnitude:
Left most bit is 1. so, it's negative.
Now, let's convert rest of the bits 1111111 to decimal
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
so, 11111111 from sign-magnitude to decimal is -127
Answer: -127
1's complement:
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.
11111111 is flipped to 00000000
II. Now convert this result to decimal value
Converting to decimal
=>
=>
=>
=> 0
Answer: 0
2's complement:
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.
11111111 is flipped to 00000000
II. Add 1 to above result
00000000 + 1 = 00000001
III. Now convert this result to decimal value
Converting 1 to decimal
1
=> 1x2^0
=> 1x1
=> 1
=> 1
Answer: -1