Jump to content

Recommended Posts

~ reverses all bits. So 0 in 8 bits is... 00000000 (binary) or 0x00 (hex)

and ~0 is the reverse of that, which is... 11111111 (binary) or 0xff (hex)

this number, 0xff, is -1 in binary.

 

To find out why negative numbers are represented in this way (why is -1 0xff and not 10000001//0x81?) you can read up on two's complement. The main reason for this binary representation comes down to making it much easier to represent negative numbers at a lower level. Eg, subtraction is simply addition of a negative number, addition of negative numbers can be done without special cases in the same circuitry as addition of positive numbers, etc.

  • 3 weeks later...

~ reverses all bits. So 0 in 8 bits is... 00000000 (binary) or 0x00 (hex)

and ~0 is the reverse of that, which is... 11111111 (binary) or 0xff (hex)

this number, 0xff, is -1 in binary.

 

To find out why negative numbers are represented in this way (why is -1 0xff and not 10000001//0x81?) you can read up on two's complement. The main reason for this binary representation comes down to making it much easier to represent negative numbers at a lower level. Eg, subtraction is simply addition of a negative number, addition of negative numbers can be done without special cases in the same circuitry as addition of positive numbers, etc.

 

so with two's complimentary, I would calculate the numerical value of a binary string the normal way unless the most significant(left most?) bit is equal to 1.  Is that correct?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.