Understanding offset-k method of representing negative integers

306 Views Asked by At

I'm reading this article about offset-k method of representing negative integers. Can someone please explain the following passage using some examples:

One logical way to represent signed integers is to have enough range in binary numbers so that the zero can be offset to the middle of the range of positive binary numbers. Then the magnitude of a negative binary number can be simply subtracted from that zero point.

I understand the mechanics, e.g. to represent number 4 in 11 bits, I'll do 4+1023=1027, but can't understand the logic behind it and why it works.

1

There are 1 best solutions below

5
On BEST ANSWER

Suppose you have a 11-bit binary number $a_1a_2\dotsm a_{11}$, where each of the $a_i$ is a binary digit (0 or 1). In the normal interpretation of binary numbers, the value of this would be $2^{10}\cdot a_1 + 2^9\cdot a_2 + \dotsb + 2^0\cdot a_{11}$. However, when you're using the offset system, the value is taken to be $2^{10}\cdot a_1 + 2^9\cdot a_2 + \dotsb + 2^0\cdot a_{11}\ \mathbf{-\ (2^{10} - 1)}$.

In this system, the number 0 is represented by $01111111111 = 2^{10} - 1$; 4 is represented by $10000000011$; and $-4$, by $01111111011$. It is called the 'offset' system because the lowest number you can represent is 'offset' from 0 by $2^k - 1$ or in other words, you 'start counting' from a negative number. Note that $4 + (-4) = 0$ still holds, as do all the other properties of addition, because this is simply a different way of representing numbers, not defining them or their axioms.