How to convert from two's complement to single precision?

oldrich.florian

Beta member
Messages
2
Location
Czech Republic
Hello,
Does anybody know how can I convert a number coded in two's complement to single precision?

I have
1111111111110011
in two's complement

and I need to convert it to single precision.

Thank you for your replies.
 
Use the first character from the left as sign indicator (in this case, negative).

Then convert 111111111110011 as 16384 + 8192 + 4096 ... 16 + 2 + 1, which yields 32755.
 
Use the first character from the left as sign indicator (in this case, negative).

Then convert 111111111110011 as 16384 + 8192 + 4096 ... 16 + 2 + 1, which yields 32755.

Isn't it 1 bit for sign indicator, 8 bit for exponent and the rest for mantissa?
Like this:
590px-Float_example.svg.png
 
Ack, I messed up. Let's try again.

So you have this number: 1111111111110011

Invert it first because the leftmost digit denotes negative sign: 0000000000001100

Plus 1, i.e.: 0000000000001101

Conversion to decimal yields 13. So the result is -13.
 
BTW, in response to the image file you posted. It refers to float I believe. Two's complement is all about int.
 
Back
Top Bottom