A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Conversion of negative binary number to decimal number
Joined: May 06, 2004
May 06, 2004 10:11:00
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.
Joined: Jun 02, 2003
May 06, 2004 11:16:00
You can convert it to an int, and then convert this into a byte:
int i = Integer.parseInt ("11111111", 2); byte b = (byte) i;
The casting in the second line is needed, to avoid the compilerwarning 'possible loss of precision'.
I agree. Here's the link:
subject: Conversion of negative binary number to decimal number
Two's complement question
No 'E' in a big floating point number
convert negative decimal number to binary
Questions about switch ... case ?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015