• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

-1 in binary?

Cooky

Golden Member
hello all,
Is -1 (decimal)
A: 11111110 or
B: 11111111 in binary?

Where can I find out how to translate between negative decimal and binary numbers?? Only know how to do positive ones...some websites you guys would recommand??
Thanks.
 
Makes sense..

So 00000000 is 0, 00000001 is 1, and 11111111 is -1. Maximum positive signed integer in binary would be 01111111 (?? I think... yeah, the extra bit is for signed/unsigned, and halves its maximum size), and 1000000 through 11111111 are negative. Something like that anyways.
 
Thanks for your quick replies.
Could someone please tell me how the translation works though?

Do I just put 1's all the way to the last bit of most significant part?
In the book I'm reading -64 is 11000000 but -192 is 11111111,11111111,11111111,01000000 (as an int instead of a byte), which doesnt work the way I thought it would...
 
It depends on the representation used. There are three representations (that I know of): signed magnitude, one's complement and two's complement. Two's complement is probably the most common and goes like this:

Take the positive of the number you want to represent in binary as a negative (e.g., if you want -55 in binary, first start with 55), then flip all the bits (do a bitwise NOT) and add one. One's complement is similiar, except you don't add one after you flip the bits, and in signed magnitude you just use the sign bit to tell if the number is positive or negative (1 for negative, 0 for positive) and treat the remaining bits as you normally would.
 
Think of it like this:
If the most significant bit is a 1, it counts as negative.

so, if you have 1000 the 1 is counted as a -8 instead of an 8. So, 1000 = -8, 1100 = 4 (because only the most significant bit is negative, the rest still count positive). 1010 is -6, 1110 is -2, etc.

I hope that made sense.
 
Back
Top