File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes negative number in binary Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "negative number in binary" Watch "negative number in binary" New topic

negative number in binary

Tony Xu

Joined: Sep 27, 2001
Posts: 27
Hi, can anybody help? Thanks in advance.
what i know is to get the binary format of positive numbers, like 25:
25 = 1 + 8 + 16, that is
0000 0001 ///this is one
0000 1000 //this is eight
0001 0000 //this is sixteen
0001 1001 //this is what i want: twenty five in byte type
00000000 00000000 00000000 0001 1001 //is 25 in int type
while, i have no idea how to get -25. as i know it would be different in byte than in int. Is the difference is to add all "one" before the -25 in byte format, which i don't know how to get?
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2591

Hi Tony,
I had replied to Jody's similar post earlier, have a look at that thread and see if it is of any help.
Here is the thread
Don't know if it (my reply) makes any sense.
- Manish
I agree. Here's the link:
subject: negative number in binary
It's not a secret anymore!