0
$\begingroup$

I'm reading up on bitwise operators, complements, and two's complements, and I'm wondering why the lower limit of a range (aka lowest negative number) isn't all zeroes in binary, and the upper limit isn't all ones.

For example, for 8 bit integers, why don't we represent -128 as 0000 0000, -127 as 0000 0001, -1 as 0111 1111, 0 as 1000 0000, and +127 as 1111 1111?

$\endgroup$
3
  • $\begingroup$ What benefit do you feel that this would have? $\endgroup$ – David Richerby Jul 31 '19 at 16:47
  • $\begingroup$ @DavidRicherby for me personally, I'm just more accustomed to thinking of things in a range. My brain naturally gets 256 sequential numbers, starting at some arbitrary point and incrementing up by 1 a total of 255 times. However, I find from 0111 1111 being +127 and 1000 0000 being -128 to be rather confusing`. $\endgroup$ – popedotninja Jul 31 '19 at 17:01
  • 1
    $\begingroup$ Have you tried doing any arithmetic with numbers in two's complement and with numbers in your suggested format? $\endgroup$ – David Richerby Jul 31 '19 at 17:05
1
$\begingroup$

This would make it basically impossible to implement the C language. In the C language, a value that can represented both as a signed and unsigned integer must have the same bit representation.

There are other problems, like you can’t use the same hardware for adding signed and unsigned integers, conversion between signed and unsigned requires an actual hardware operation.

$\endgroup$

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.