File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCM Java EE 6 Enterprise Architect Exam Guide
this week in the
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'.
It is sorta covered in the
JavaRanch Style Guide
subject: Conversion of negative binary number to decimal number
No 'E' in a big floating point number
Questions about switch ... case ?
convert negative decimal number to binary
Two's complement question
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014