radixflip

Two's Complement & IEEE 754 Converter

Signed integers to two's complement bits, and decimals to IEEE 754 float bits, with every field shown and a reverse converter for both.

Two's Complement

Two's complement back to decimal

IEEE 754 Floating Point

Float bits back to decimal

1's & 2's complement →  ·  Binary calculator →

How to convert two's complement and IEEE 754

  1. Pick a width or precision. Choose 8, 16, 32 or 64 bits for two's complement, or 32 or 64 bits for IEEE 754.
  2. Type a number. Enter a whole number for two's complement or any decimal for IEEE 754.
  3. Read the bits. The binary, hex and field breakdown update live.
  4. Go backwards. Type bits or hex in the reverse box to get the value back.

Worked examples

NumberFormatBits / hexStored value
−58-bit two's complement11111011 (FB)−5
−1288-bit two's complement10000000 (80)−128
0.132-bit float3DCCCCCD0.10000000149011612
0.164-bit float3FB999999999999A0.1
12.37532-bit float4146000012.375 exactly

12.375 is exact because it is 12 + 3/8, and 3/8 is a sum of powers of two (1/4 + 1/8). 0.1 has no exact binary form, so the stored value is the nearest float, slightly above 0.1 in both precisions.

Frequently asked questions

What is two's complement?

Two's complement is how computers store signed whole numbers in a fixed number of bits. Positive numbers look the same as unsigned binary. A negative number is stored as 2^N plus the number: with 8 bits, −5 becomes 256 − 5 = 251, which is 11111011. The top bit is the sign bit: 1 means negative, 0 means zero or positive.

What range fits in N bits?

With N bits in two's complement, the range runs from −2^(N−1) to 2^(N−1) − 1. So 8 bits hold −128 to 127, 16 bits hold −32768 to 32767, and 32 bits hold −2147483648 to 2147483647. One more negative value fits than positive values, because 0 takes one of the positive slots. If your number falls outside the range, pick a wider width.

How do I read a two's complement bit string back?

If the top bit is 0, read it as an ordinary binary number. If the top bit is 1, the value is the unsigned value minus 2^N. Example with 8 bits: 11111011 is 251 unsigned, and 251 − 256 = −5. Type the bits in the reverse box above to check any string.

What is IEEE 754?

IEEE 754 is the standard for floating point numbers. A 32-bit float has 1 sign bit, 8 exponent bits and 23 mantissa bits; a 64-bit float has 1 sign bit, 11 exponent bits and 52 mantissa bits. The exponent is stored with a bias (127 for 32-bit, 1023 for 64-bit), and the mantissa holds the digits after the leading 1. The converter above splits any number into those three fields.

Why is 0.1 not exact in floating point?

0.1 cannot be written exactly in binary, just as 1/3 cannot be written exactly in decimal. The nearest 32-bit float to 0.1 is 0.10000000149011612, stored as hex 3DCCCCCD. The 64-bit float is much closer, 0.1000000000000000055511151231257827, stored as 3FB999999999999A. That tiny gap is why 0.1 + 0.2 prints as 0.30000000000000004 in most languages.

What are subnormals, infinity and NaN?

When the exponent bits are all 0 and the mantissa is not 0, the number is subnormal: a very tiny value close to zero, with less precision. When the exponent bits are all 1 and the mantissa is 0, the value is infinity (positive or negative by the sign bit). When the exponent bits are all 1 and the mantissa is not 0, the value is NaN, meaning not a number, which is what 0/0 produces.

1's & 2's complement →  ·  Binary calculator →