aspose file tools*
The moose likes Beginning Java and the fly likes how to represent a negative number by bit? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to represent a negative number by bit?" Watch "how to represent a negative number by bit?" New topic
Author

how to represent a negative number by bit?

Jello Yao
Greenhorn

Joined: Jan 05, 2003
Posts: 13
Any one please help explain how to represent a negative number by bit? Please give a few examples. Thanks!
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Hello Jello,
Though it makes for a nice rhyme, your display name doesn't quite fit the famous JavaRanch naming policy. Could you please take a minute to change your display name to show 2 names, preferably your real name. (It's all about maintaining our professional image - don't let the one-eyed moose fool you!).
Thanks and hope you'll be visiting the ranch often,
Pauline
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Any bit-type number that has a "1" in the highest position is negative.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jello Yao
Greenhorn

Joined: Jan 05, 2003
Posts: 13
What is the bit representation for -5? I know how to do it for 5(00000101). But I do not know how to do it for a negative number? Any tips?
Thanks!
boyet silverio
Ranch Hand

Joined: Aug 28, 2002
Posts: 173
follow the ff:
binary of decimal 5 00000101
change all 0 to 1, vice versa 11111010
add 1 00000001
========
corresponding value of -5 11111011

to check:
binary of -5 11111011
change 0 to 1, vice versa 00000100
add 1 00000001
========
results to binary of 5 00000101
[ January 05, 2003: Message edited by: boyet silverio ]
[ January 05, 2003: Message edited by: boyet silverio ]
Jello Yao
Greenhorn

Joined: Jan 05, 2003
Posts: 13
Big thanks! I'm clear about this now.
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

Have alook at this, and see if it is of any help.
HTH,
- Manish
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
In fact, the highest bit is a sign bite, only showing sign.
For example, for byte, there are 8 bites, but the range is from -2^7 to 2^7-1
2^7 - 1 = 0111 1111 ;
If you add 1 more, the highest bite will become 1, which means negative.
Jello Yao
Greenhorn

Joined: Jan 05, 2003
Posts: 13
Big thanks!
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
You are welcome!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to represent a negative number by bit?