0
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ thanks, so using this system, with 11 bits, the number $0000 0000 000$ is negative 1023 (2 ^ 10 - 1)? $\endgroup$ – Maxim Koretskyi May 23 '16 at 8:21
  • $\begingroup$ @Maximus Yes. The same logic works for any number of bits. $\endgroup$ – shardulc says Reinstate Monica May 23 '16 at 8:39
  • $\begingroup$ thanks, can you please also explain how you get the following: $4$ is represented by $10000000011$; and $−4$, by $01111111011$ - working from $0111 1111 111$? $\endgroup$ – Maxim Koretskyi May 23 '16 at 8:44
  • $\begingroup$ @Maximus We know that 0 is represented by $2^10 - 1 = 01111111111$. Now we can add $4 = 100$ to this like normal binary. $\endgroup$ – shardulc says Reinstate Monica May 23 '16 at 8:48
  • $\begingroup$ thanks a lot, I understand now. If you have time, can you please take a look at my this related question. $\endgroup$ – Maxim Koretskyi May 23 '16 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.