Skip to main content
GameDev.net gamedev.net
🔒 Locked

Convert Binary to Decimal in Java

Started by Fernand Jan 6, 2005 at 2:39 PM 1 replies 350+ views
Original Post
Fernand
Fernand
HI, How can I make this conversion with negative binary numbers?? The method Integer.parseInt(bin,2) don´t function to negative values?? Thanks, Fernand
Fruny
Fruny
If your number is greater than 2147483647 (231-1), then substract 4294967296(232) from it.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Zahlman
Zahlman
Java ints are signed, so I don't think that will be of use :s

How exactly are you expecting a 'negative binary number' to be represented? With an actual negative sign on the front? Or in 2s complement?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.