Arithmetic Quiz - Answers
3710 = 1001012
10100101
11011010
11011011
−37 = −37 + 256 = 219 = 11011011
Note: the range of representable numbers is −256 to −1 (!)
−37 = −37 + 128 = 91 = 01011011
This is the more usual range. i.e. −128 to +127
−2n−1−1 to +2n−1−1, where n = 10, i.e. −511 to +511
−2n−1−1 to +2n−1−1, where n = 10, i.e. −511 to +511
−2n−1 to +2n−1−1, where n = 10, i.e. −512 to +511
−2n−1 to +2n−1−1, where n = 10, i.e. −512 to +511
9 | 8 | 7 | 6 | 5 |
1001 | 1000 | 0111 | 0110 | 0101 |
"invert the bits and add 1" 11100110 + 1 = 11100111
check:
11100111 = −128 + (64 + 32 + 4 + 2 + 1) = −2510
"invert the bits and add 1" 11100001 + 1 = 11100010
check:
11100010 = −128 + (64 + 32 + 2) = −3010
"invert the bits and add 1" 10010111 + 1 = 10011000
check:
10011000 = −128 + (16 + 8) = −10410
"invert the bits and add 1" 10001011 + 1 = 10001100
check:
10001100 = −128 + (8 + 4) = −11610
by comparing the resulting bitpatterns to the originals, can you spot a "short cut" method for the conversion?
Take another look at the bit patterns:
positive:
00011001
00011110
01101000
01110100
negative:
11100111
11100010
10011000
10001100
"starting from the rightmost bit (lsb), copy each bit unchanged up to and including the first 1 then invert all the remaining bits"
1010 1010 1011 −1011 0000 1101
Two's Complement subtraction: "negate the subtrahend and add"
Two's Complement negation: "invert the bits and add 1"
101100001101 = 010011110010 + 1 = 010011110011
1010 1010 1011 +0100 1111 0011 -------------- 1111 1001 1110
Check your answer by determining the decimal representation of the numbers and the result
1010 1010 1011 = −2048 + 683 = −1365 −1011 0000 1101 = −(−2048 + 781 = −1267) -------------- ----- 1111 1001 1110 = −2048 + 1950 = -98
last updated: 24-Oct-06 Ian Harries <ih@doc.ic.ac.uk>