Two Laptop Bag
The moose likes Beginning Java and the fly likes Conversion of negative binary number to decimal number Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Conversion of negative binary number to decimal number" Watch "Conversion of negative binary number to decimal number" New topic
Author

Conversion of negative binary number to decimal number

nagajyothi Avusingi
Greenhorn

Joined: May 06, 2004
Posts: 1
if we have a byte value EX: 11111111 where 1 in first digit place shows that its negative number, how to get back the decimal number which will be negative.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

You can convert it to an int, and then convert this into a byte:

The casting in the second line is needed, to avoid the compilerwarning 'possible loss of precision'.


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Conversion of negative binary number to decimal number
 
Similar Threads
No 'E' in a big floating point number
Two's complement question
convert negative decimal number to binary
Questions about switch ... case ?
Shift Operators