Reputation: 1683
I am using Integer.toBinaryString to convert floats to intbits (Float.floatToIntBits()) into binary. However, the result is unsigned. Is there a way I can get a signed base two result? I am not looking for a two's compliment representation.
I also want to do the reverse, turned a signed binary number to float.
Upvotes: 0
Views: 304
Reputation: 79875
If value
is the int
that you want to convert, you could do something like
value < 0 ?
( "-" + Integer.valueOf(-value).toBinaryString()) :
Integer.valueOf(value).toBinaryString();
I don't want to answer your second question here - you added it after I posted this.
Upvotes: 1