-1 in binary?

Cooky

Golden Member
Apr 2, 2002
1,408
0
76
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.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
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.
 

Cooky

Golden Member
Apr 2, 2002
1,408
0
76
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...
 

cjohnson

Junior Member
Oct 10, 2002
21
0
0
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.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
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.