# Floating-Point Value

> A floating-point number stores a value as a sign, a power of two and a binary fraction, and this formula turns those three parts back into the number.

Page: https://formulabro.yunusemrevurgun.com/computer-science/floating-point-value/  
Category: Computer Science  
Published: 2026-10-22  
Updated: 2026-10-22

## Formula

$$
x = (-1)^{s} \times 1.f \times 2^{e - 127}
$$

Read it out loud: "x equals negative one to the power of s, times 1 point f, times 2 to the power of e minus 127. This form covers normal single-precision numbers. x is the number the 32 bits stand for. s is the sign bit, 0 for positive and 1 for negative. 1 point f is the significand: a 1, a point, then the 23 stored fraction bits f. e is the exponent field, the 8 stored bits read as a whole number. The 2 with e minus 127 as a small raised number is the scale, two multiplied by itself that many times."

## Before you start

- **Powers of ten and scientific notation, like $10^{38}$**: $10^{38}$ means 1 followed by 38 zeros, a number so large that it is written as a power. A **power of ten** is ten multiplied by itself a set number of times, and the small raised number is the exponent. Scientific notation writes a number as a short number times a power of ten. So $3.4 \times 10^{38}$ means 3.4 with the decimal point moved 38 places to the right. A negative exponent moves the point to the left, so $10^{-3} = 0.001$.
- **Binary fractions, like $0.1_{2}$**: A **binary fraction** works like a decimal fraction, but each place is a power of two. The places after a binary point are worth $\frac{1}{2}$, $\frac{1}{4}$, $\frac{1}{8}$ and so on. So $0.1_{2}$ means one half, $0.01_{2}$ means one quarter, and $0.11_{2}$ means three quarters. A fraction such as one tenth has no finite binary form, as the explanation below shows.
- **Bits, bytes and 32-bit numbers**: A **bit** is one 0 or 1. A **byte** is 8 bits. A **32-bit** number is a pattern of 32 bits, which is four bytes. The computer can only store a fixed number of bits for each number, so every decimal value it keeps has to fit inside those 32 bits. That limit is the reason floating-point numbers are sometimes not exact.
- **Hexadecimal and the prefix 0x**: **Hexadecimal** is base 16, which uses the digits 0 to 9 and the letters A to F. One hex digit stands for exactly four bits. The prefix **0x** shows that the digits that follow are hexadecimal. So $\text{0x3DCCCCCD}$ is a 32-bit pattern written in eight hex digits, and the hex digit D stands for the four bits 1101.
- **The IEEE 754 standard**: **IEEE 754** is the standard that defines how computers store decimal values as binary floating-point numbers. Most processors follow it, so the same bits give the same number on different machines. The standard defines several sizes. This page covers the most common one, single precision, which uses 32 bits.

More notation help: https://formulabro.yunusemrevurgun.com/math-basics/

## What each symbol means

- $x$: The **number** that the 32 bits stand for. It is a decimal value with no unit of its own, and its size depends on the bits. The example pattern stands for $x = 6$.
- $(-1)^{s}$: The **sign factor**. It equals $+1$ when the sign bit is 0, and $-1$ when the sign bit is 1. It has no unit, and it only decides whether the number is positive or negative.
- $s$: The **sign bit**, the first of the 32 bits. It is 0 for a positive number and 1 for a negative number. It has no unit, because it is one bit.
- $1.f$: The **significand**, a binary number from 1 up to nearly 2. Its leading 1 is implied and not stored, and the 23 stored fraction bits follow the binary point. It has no unit. It holds the digits of the number itself.
- $f$: The **23 stored fraction bits**, written after the leading 1. Bit by bit they are worth one half, one quarter, one eighth and so on. They have no unit and are read as a binary fraction.
- $e$: The **exponent field**, 8 stored bits read as a whole number from 0 to 255. It has no unit. The real power of two is $e - 127$, which is why the field is said to have a bias of 127.
- $2^{e - 127}$: The **scale factor**, a power of two that sets the size of the number. It has no unit. A stored exponent of 130 gives a real power of $130 - 127 = 3$, so the scale is $2^{3} = 8$.

## The formula piece by piece

- $f$: The 23 stored fraction bits, the smallest detail of the number. Each bit that is 1 adds a fraction, such as one half or one quarter, to the significand. Together they give the digits after the leading 1.
- $1.f$: Add the implied leading 1 to the fraction. The result is a binary number from 1 up to nearly 2. An all-zero fraction gives exactly 1, and a fraction of one half gives 1.5.
- $(-1)^{s}$: The sign factor from the sign bit. If the sign bit is 0, the factor is $+1$ and the number stays positive. If it is 1, the factor is $-1$ and the number becomes negative.
- $2^{e - 127}$: The scale factor from the exponent field. Subtract the bias 127 from the stored exponent to get the real power, then raise 2 to that power. A stored exponent of 127 gives a scale of 1, and a stored exponent of 128 gives a scale of 2.
- $x = (-1)^{s} \times 1.f \times 2^{e - 127}$: The whole formula in one sentence: the number equals the sign factor times the significand times the scale factor, so the sign, the digits and the size are combined into one decimal value.

## What the formula is doing, and why

**What goes in and what comes out.** You give the formula 32 bits: one sign bit $s$, eight exponent bits $e$ and 23 fraction bits $f$. It returns the decimal number $x$ that those bits stand for. This 32-bit form, called single precision, is one of the most common ways that computers store decimal numbers.

**Why it works like scientific notation.** A number such as $6.02 \times 10^{23}$ has a sign, a string of digits and a power that sets its scale. A floating-point number does the same in base two. The fraction bits are the digits, the exponent is a power of two that moves the binary point to the right size, and the sign bit gives the plus or minus.

**Why the leading 1 is not stored, and why the bias is 127.** Every normal number can be scaled so that its binary digits start with 1, as in $1.\ldots$. Because that leading 1 is always present, the format does not store it, and this gives one more bit of precision. The stored exponent is a whole number from 0 to 255, so the bias 127 is subtracted to give a real power from $-126$ up to $127$.

**Why 0.1 is not exact.** In binary, one tenth is $\frac{1}{10}$, and its denominator has a factor of 5. A fraction has a finite binary form only when its denominator, in lowest terms, is a power of two. So $0.1$ repeats forever in binary, as $0.0001100110011\ldots$, with the pattern 0011 repeating. The 23 fraction bits cut the pattern off, so the stored value is $0.100000001490116\ldots$. That is very close to 0.1, but it is not equal to it.

**Limits of the format.** A single-precision value keeps about 7 decimal digits. Whole numbers are exact only up to $2^{24} = \text{16,777,216}$. The largest finite value is about $3.4 \times 10^{38}$. Exponent field values 0 and 255 are reserved for zero, very small numbers, infinity and not-a-number, so the normal formula above covers exponent fields 1 to 254.

## An everyday picture

Scientific notation on a calculator is the closest everyday idea. The display has room for a fixed number of digits, such as $6.02 \times 10^{23}$, and the exponent moves the decimal point to the right size. Floating point does the same with bits. The 23 fraction bits are the fixed digits, and the exponent is the power of two that sets the scale.

## Worked example: Decoding a 32-bit float

Suppose a game stores one number, the size of a sprite on screen, as the 32 bits $0\ 10000001\ 10000000000000000000000$. These are the sign, the eight exponent bits and the 23 fraction bits, in that order. So $s = 0$, the stored exponent field is $e = 129$, and the fraction bits give $f = 0.1000\ldots$ in binary, which is one half.

1. **Split the 32 bits into three parts.** The first bit is the sign bit, the next eight bits are the exponent field, and the last 23 bits are the fraction. Counting them gives $1 + 8 + 23 = 32$, so the split uses every bit exactly once.
2. **Read the sign.** The sign bit is $s = 0$, so the sign factor is $(-1)^{0} = 1$. Multiplying by 1 changes nothing, so the number is positive.
3. **Read the exponent field.** The eight bits $10000001$ stand for $128 + 1 = 129$. The real power of two is $129 - 127 = 2$, because the bias 127 is subtracted from the stored value. So the scale factor is $2^{2} = 4$.
4. **Read the fraction bits.** The 23 fraction bits begin with a 1 and then have 22 zeros. The first bit after the binary point is worth one half, and the rest add nothing. So $f = 0.5$, and the significand is $1.f = 1 + 0.5 = 1.5$.
5. **Multiply the three parts.** The formula says $x = (-1)^{s} \times 1.f \times 2^{e - 127}$, which here is $1 \times 1.5 \times 4 = 6$. The sign is positive, the significand is 1.5, and the scale is 4, so these 32 bits store exactly the number 6.
6. **Check a value that is not exact.** The 32-bit pattern for 0.1 is $\text{0x3DCCCCCD}$. Its sign bit is 0, and its exponent field is $01111011$, which is 123, so the real power is $123 - 127 = -4$. Its 23 fraction bits are a pattern that is cut off, so the significand is about $1.6000000238$. Multiplying gives $1.6000000238 \times 2^{-4} = 0.1000000015$, which is close to 0.1 but not equal to it.

**Answer:** The 32 bits store exactly **6**, because the sign is positive, the significand is 1.5 and the scale is 4. Many decimal values, such as 0.1, have no exact binary form, so the computer stores the nearest pattern instead. For 0.1 that stored value is about **0.1000000015**.

## Common mistakes

- Expecting decimals to be stored exactly. In Python, $0.1 + 0.2$ with ordinary 64-bit floats gives $0.30000000000000004$, not $0.3$, because each value is rounded to binary first.
- Forgetting the implied leading 1. The stored fraction bits are not the whole significand. An all-zero fraction with a normal exponent means $1.0$, not $0$.
- Forgetting the bias. A stored exponent of 130 is a real exponent of 3, so subtract 127 before you use it as a power of two.
- Assuming every whole number is exact. Single precision stores whole numbers exactly only up to $2^{24} = \text{16,777,216}$. The value $\text{16,777,217}$ rounds to $\text{16,777,216}$.
- Testing floats with $==$ after arithmetic. Compare them with a small tolerance instead, because rounding errors add up.

## Where you will meet it

- Graphics and game engines, where positions, colors and lighting values are often 32-bit floats.
- Scientific computing in Python, such as the float32 and float64 types in the NumPy library.
- Machine learning, where model weights and activations are often stored as 32-bit or 16-bit floats.
- Java's float and double types, which follow IEEE 754.

## Questions people ask

### Why is 0.1 not exact in binary?

Because $\frac{1}{10}$ has a factor of 5 in its denominator, and a fraction has a finite binary form only when its denominator, in lowest terms, is a power of two. Decimal has the same kind of problem with $\frac{1}{3} = 0.333\ldots$, which never ends.

### What is the difference between single and double precision?

Double precision uses 64 bits: 1 sign bit, 11 exponent bits and 52 fraction bits. It keeps about 15 to 16 decimal digits, compared with about 7 for single precision.

### Should I use floats for money?

Not for exact totals. Store amounts as whole cents in an integer, or use a decimal type designed for money. Binary rounding can make totals a cent off.

## Related formulas

- [Binary Number Value](https://formulabro.yunusemrevurgun.com/computer-science/binary-number-value/)
- [Two's Complement](https://formulabro.yunusemrevurgun.com/computer-science/twos-complement/)
- [Hexadecimal Number Value](https://formulabro.yunusemrevurgun.com/computer-science/hexadecimal-number-value/)
- [Bits Needed](https://formulabro.yunusemrevurgun.com/computer-science/bits-needed/)

## Sources

- [IEEE 754, Wikipedia](https://en.wikipedia.org/wiki/IEEE_754)
- [Single-precision floating-point format, Wikipedia](https://en.wikipedia.org/wiki/Single-precision_floating-point_format)

From Formula Bro (https://formulabro.yunusemrevurgun.com/), a side project developed by yunusemrevurgun.com.
