Skip to content
Aarrange

Float to Binary

Paste decimal floats, one per line. Get the IEEE 754 sign, exponent and mantissa bits, with the steps. Nothing leaves your browser.

Also: All formats, Float to Hex, Hex to Float

0
Numbers
0
Rounded
0
Errors
Input
Tab types a tab. Press Escape, then Tab, to leave the editor.
Result
The result shows here as you type.Try , or .
On this page

About Float to Binary

Updated

Float to Binary shows the bits a computer stores for a decimal number: the sign, the exponent and the mantissa, as the IEEE 754 standard sets them. It is made for the class exercise and for the bug where a float is not quite the number you typed.

Open Steps to see the work by hand, with the doubling table for the fraction. Open Bits to click any bit and watch the value change: flip the last mantissa bit of 1 and you get 1.0000001.

The same tool, set up for other jobs: IEEE 754 Converter, Float to Hex, Hex to Float. For whole numbers in any base, use the Number Base Converter.

How to use it

  1. Paste decimal numbers or binary bits, one per line, or load a file. Tabs, semicolons and a comma with a space after it also split a line.
  2. Pick the Format: 16-bit half, bfloat16, 32-bit single, 64-bit double or 128-bit quad. It is in the Result header. On a phone it is under More.
  3. Check From and To, next to Convert. On a phone they are under More.
  4. Press Convert (Alt C). Results shows each answer and how much it was rounded. When a number is rounded, the Value column shows the exact value that is stored. A long value is cut short there, and Bits shows all of it. Output has only the answers, for Copy and Download.
  5. Open Bits to see the sign, exponent and mantissa of one number. Click a bit to flip it, or step to the next float up or down. Steps shows the work by hand.
  6. Swap (Alt S) puts the answers in the editor and turns From and To around, so you can check the way back.

A worked example: -10.5

Float to binary
1. Sign        negative                  1
2. Binary      10.5 = 1010.1
3. Normalise   1.0101 x 2^3
4. Exponent    3 + 127 = 130             10000010
5. Mantissa    after the point: 0101     01010000000000000000000

Result         1 10000010 01010000000000000000000   (hex C1280000)

A fraction that never ends

0.1 in binary
0.1 x 2 = 0.2   0
0.2 x 2 = 0.4   0
0.4 x 2 = 0.8   0
0.8 x 2 = 1.6   1
0.6 x 2 = 1.2   1
0.2 x 2 = 0.4   0    and the pattern 0011 repeats forever

0.1 = 0.000110011001100110011...  =  1.1001100110011... x 2^-4

A 32-bit float keeps 23 bits after the first 1 and rounds the rest. A 64-bit double does the same with 52 bits. That is why 0.1 + 0.2 gives 0.30000000000000004 in JavaScript and Python.

Bits in each format

IEEE 754 formats
Format     Bits  Sign  Exponent  Mantissa  Bias   Digits  Largest
half         16     1         5        10     15    3.3    65504
bfloat16     16     1         8         7    127    2.4    3.39e38
single       32     1         8        23    127    7.2    3.40e38
double       64     1        11        52   1023   16.0    1.80e308
quad        128     1        15       112  16383   34.0    1.19e4932

Common errors

A decimal comma

In much of Europe, one and a half is written 1,5. Other converters read it as 1 or as 0, with no warning. This tool marks the comma. A comma with a space after it splits two numbers, so a list such as 0.1, 0.2 still works.

Invalid
1,5
Decimal comma. Write 1.5 with a point. For two numbers, put a space
after the comma.
Fixed
1.5

An exponent with no digits

A number copied from a log can lose its end. The tool marks the e.

Invalid
6.02e
Exponent has no digits. Put the power of ten after the e: 1e5 or 2.5e-3.
Fixed
6.02e23

A whole number that is not exact

This one is not an error, but it surprises people. A 32-bit float holds every whole number up to 16,777,216 (2^24). Past that, only every second one. 16777217 is stored as 16777216, and the tool says so in a note.

Float to binary resources

Float to binary FAQ

How do I convert a decimal to IEEE 754 binary?

Five steps. 1. The sign bit: 0 for positive, 1 for negative. 2. Write the number in binary: the whole part by dividing by 2, the fraction by doubling. 3. Move the point so one 1 is in front: 1.xxx × 2^e. 4. Add the bias (127 for 32-bit) to e and write it in 8 bits. 5. Keep 23 bits after the point, rounded to the nearest.

Paste your number and open Steps to see each step with your numbers.

What is 0.1 in IEEE 754 binary?

In 32-bit: 0 01111011 10011001100110011001101. The pattern 1001 repeats forever, so the last bit is rounded up. The stored value is 0.100000001490116119384765625.

How do I convert a fraction to binary?

Double it again and again. Each time, the whole part (0 or 1) is the next bit, and you go on with what is after the point. For 0.375: 0.75 → 0, 1.5 → 1, 1.0 → 1. So 0.375 is 0.011 in binary.

If the fraction never reaches 0, the bits go on forever, as they do for 0.1.

What is the bias in the exponent?

A number added to the exponent so it is always stored as a positive number. It is 127 for 32-bit, 1023 for 64-bit and 15 for 16-bit. An exponent field of 01111111 (127) means 2^0.

What is the hidden bit?

Every normal float starts 1.xxx in binary, so that 1 is not stored. A 32-bit float keeps 23 mantissa bits and has 24 bits of precision. Subnormals have an exponent of all zeros and no hidden 1.

How do I convert binary back to a float?

Paste the 32 bits here as one run of zeros and ones, such as 01000001110010000000000000000000. A run of exactly 32 (64 in 64-bit) is read as bits, not as a decimal. For one number the Bits view opens: it shows the value, 25, and each field. For a list, Results shows each value.

To get only the decimals, press Swap (Alt S): the bits stay in the editor, From becomes Binary bits and To becomes Decimal.

Are my numbers sent anywhere?

No. Every number is converted in your browser, with exact BigInt math. Nothing is uploaded, and there are no ads or cookie walls. You can check this in your browser's network tab while you use it.