So I understand the logic behind converting positive decimal numbers to IEEE 32 bit floating numbers but I'm not completely sure behind the negative one's. If for example we have a decimal number say -15.5, do we have to do two's complement first then convert it to the floating point representation or we directly do it for 15.5 and at the sign bit we do 1. Thank you in advance.
3 Answers
Contrary to two's complement representation of negative integers, the negative numbers in IEEE floating-point are represented with only a sign bit change, as shown in there.
For example, $0\cdot01111100\cdot01000000000000000000000$ is the representation of $0.15625$, and $1\cdot01111100\cdot01000000000000000000000$ is the representation of $-0.15625$.
In particular, there are two representations of zero (the positive one and the negative one).
IEEE floating point numbers have a sign bit. The representation of $-x$ is generally the same as that of $x$, with the sign bit flipped. This has the unfortunate consequence of having two different zeroes.
To get the binary representation for -x in IEEE754 floating point format, you start with the binary representation of x, then change the sign bit. That’s it.