GeeCON Prague 2014*
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


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "negative number in binary" Watch "negative number in binary" New topic
Author

negative number in binary

Tony Xu
Greenhorn

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: 2578

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.
Regards,
- Manish
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: negative number in binary