Beetwise

Convert a float to binary

A 32-bit float holds a sign bit, an 8-bit exponent and a 23-bit fraction.

The float 1.0 has the bits 0x3F800000.

The bit editor holds a float field at a bit width of 32, so a value converts both ways.

Try float to binary conversion in the bit editor

The float 1.0, which is 0x3F800000. Edit the expression or select a bit to flip it.

31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
1
float · 32 bits
binary
0b00111111100000000000000000000000
hex
0x3F800000

Float to binary conversion step by step

Split the 32 bits of the float into its three fields: The steps follow the value above.

  1. Write the 32 bits: 00111111100000000000000000000000
  2. The sign bit is 0, so the value is positive.
  3. The next 8 bits are the exponent: 01111111, which is 127. Subtract the bias 127 to get 0.
  4. The last 23 bits are the fraction: 00000000000000000000000
  5. The value is 1.

The bits of a few float values

The bits of a few float values
FloatHexSignExponent
0.00x0000000000
1.00x3F8000000127
2.00x400000000128
-1.00xBF8000001127
0.50x3F0000000126
Infinity0x7F8000000255

Where float to binary conversion is used

A sensor that reports a float over a link sends these four bytes.

A log that stores a float as raw bytes needs the same layout to read it back.

A value that reads as a huge integer is often a float in disguise.

Float to binary conversion: points to note

  • The expression field takes a float, such as 0.5. It also takes the hex form of the bits, such as 0x3F000000.
  • Set the bit width to 32. The float field appears at that width only.
  • The same 32 bits read as 1065353216 unsigned and as 1.0 as a float.
  • A float carries about 7 decimal digits. A value with more digits loses the rest.
  • The byte order of the four bytes follows the target, so a link needs a defined order.

The full bit editor

The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.

Open this value in the full editor

Questions about float to binary conversion

What is 1.0 in binary?
The float 1.0 is 00111111100000000000000000000000, which is 0x3F800000.
Why does the exponent read 127 for the value 1.0?
The stored exponent carries a bias of 127, so a real exponent of 0 gives the stored value 127.
How do I convert the other way?
Enter the bits or the hex value at a bit width of 32. The float field shows the value.
Can I type a float directly?
Yes. Enter a value such as 0.5 in the expression field. The bits and the hex form follow it.