# The bitwise complement of a floating point number's binary representation

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.

-
Do you mean bitwise NOT? "Bitwise" encompasses many operations. Which one in particular are you referring to? –  Connor Wolf Feb 10 '11 at 11:01
I´m refering to change the ones by zeros, and the zeros by ones. –  Peterstone Feb 10 '11 at 18:36
The Binary inversion of a number (what you describe) is called the "logical NOT" operation. –  Connor Wolf Feb 11 '11 at 3:29
i believe the operation in question is also referred to as the "ones complement" :) –  vicatcu Feb 11 '11 at 4:34

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.

http://www.engrng.pitt.edu/hunsaker/3097/floatingpoint.pdf

http://floating-point-gui.de/

-
Unlike two's complement integers, IEEE 754 floating point has a positive and a negative! zero. –  joeforker Feb 11 '11 at 2:38
It also has NaN, Infinity, and 'subnormals' (the little deviants)... oh my! This number format is designed to make life simpler for numerical methods accelerated by hardware. IEEE 754 even supports decimals! (base 10): en.wikipedia.org/wiki/Decimal32_floating-point_format. –  eryksun Feb 12 '11 at 2:23

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:

FloatingPointNumber ^ 0x80000000 == -(FloatingPointNumber)


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.

-
I disagree with this comment but was not able to down vote –  BullBoyShoes Feb 10 '11 at 21:04
@Eddie Hitler To downvote you need a reputation of 125+ electronics.stackexchange.com/faq –  Toby Jaffey Feb 10 '11 at 23:41

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:

00111110 00100000 00000000 00000000 binary = 3E200000 hex


and you will see, that it's really 0.15625 decimal.

When you now enter the bitwise NOT (ones' complement) of that binary representation:

11000001 11011111 11111111 11111111 binary = C1DFFFFF hex


you will see that it is -27.999998092651367.

-
See Joby Taffey's answer for an explanation why. –  AndreKR Feb 11 '11 at 1:57
You only invert the MSB, hence in your example 0x3E20 0000 becomes 0xBE20 0000 which is infact the correct answer –  BullBoyShoes Feb 11 '11 at 10:40
You'll need a XOR operation for that. –  AndreKR Feb 11 '11 at 12:35