I wonder if the bitwise complement (NOT) of a floating point number's binary representation of a number is the same number but with a change in its sign?
Thank you to all possible references to articles or documentation.
|
I wonder if the bitwise complement (NOT) of a floating point number's binary representation of a number is the same number but with a change in its sign? Thank you to all possible references to articles or documentation. |
|||||||||||||
|
|
IEEE 754 floating point numbers are represented as a sign, a mantissa and an exponent. It is possible to work with floats at a bit level, but you need to know what you're doing.
Here are some documents which explain further. |
|||||
|
|
I'm not sure what you mean by "the bitwise." There are many bitwise operations. Logical choices are the One's complement/Bitwise NOT (Fake Name's guess) or Two's complement (changes sign for signed integers). Less logical choices are OR, AND, XOR, and their complements NOR, NAND, XNOR. None of these will produce the desired result for a floating point number. As you can see in Joby's nice diagram, the first bit is the sign bit, then the (biased) exponent occupies 8 bits, then the mantissa. What you want to do is XOR the sign bit:
That constant assumes you're using 32-bit floats. You'll need to add another 8 zeros at the end of the constant for a number of type double. |
|||
|
|
|
No, it's garbage. floating points have complex internal structure, so you cannot do that. You may do some manipulations on mantissa, but not whole number. |
|||||
|
|
No, it's not. You can try it here: http://babbage.cs.qc.edu/IEEE-754/32bit.html You can for example enter the number from the binary32 wikipedia page:
and you will see, that it's really 0.15625 decimal. When you now enter the bitwise NOT (ones' complement) of that binary representation:
you will see that it is -27.999998092651367. |
|||||||||
|