A study group writes:
Dear Professor Patt, To represent the decimal number -64 how many bits would you need? Within our study group there was a discrepancy over whether it was 7 bits or 8 bits. We know the formula for the total negative numbers represented with 2's compliment is 2 ^ (n-1), however,
Good!when writing -64 in binary we had trouble. Would it be 1000000 or would you have to write -64 as +64 in 2's compliment first and then convert it to a negative number by inverting all the bits and adding one?
So, let's look at this a little more carefully. With 7 bits, you can (as you know) represent 128 integers. The non-negative integers 0 to 63 occupy 64 of them. We can form a negative number having the same absolute value as the corresponding positive number in the way you suggest. There are 63 of them, giving values -1 to -63. So, 64 non-negatives + 63 negatives = 127 total. But with seven bits we can represent 128 integers. So, what do we do? Rather than waste the remaining code, we use it to encode the "next" negative number -64. That is the standard practice, and yes it does create a slight unbalance. And no, we can not get -64 by starting with +64 since +64 is not representable in 2's complement with 7 bits. OK?
ps. It is 2's complement, rather than 2's compliment. 2's compliment might be a remark 2 made to 5, "How big and strong you are." But the night before the exam you can probably do without my weird sense of humor.Thank You, << name withheld to protect .... >>