Skip to content

Resource · Guide or article

Binary representation of floating-point numbers

Explains how IEEE 754 stores floating-point numbers as sign, exponent and fraction bits, starting from plain 16-bit integers. Useful for candidates asked how floating-point values, including JavaScript numbers, are laid out in memory.

Reviewed

Open the original: Binary representation of floating-point numbers (opens the original site in a new tab)

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

Have you ever wondered how computers store the floating-point numbers like 3.1416 (𝝿) or 9.109 × 10⁻³¹ (the mass of the electron in kg) in the memory which is limited by a finite number of ones and zeroes (aka bits)? It seems pretty straightforward for integers (i.e. 17). Let's say we have 16 bits (2 bytes) to store the number. In 16 bits we may store the integers in a range of [0, 65535]: If we need a signed integer we may use two's complement and shift the range of [0, 65535] towards the negative numbers. In this case, our 16 bits would represent the numbers in a range of [-32768, +32767].

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Article

What it covers

  • Unsigned and two's complement 16-bit integer ranges as the starting point
  • A table of half, single and double precision bit splits: 1 sign bit plus 5, 8 or 11 exponent bits and 10, 23 or 52 fraction bits
  • The biased exponent and its formula 2^(k-1) - 1, with a diagram decoding a half-precision number
  • Range and smallest positive value tables for half and single precision
  • Links to the folder's bitsToFloat.js and floatAsBinaryString.js examples

How to use it

PrepKit study advice, not a claim made by the source.

Take a few decimal values such as -27.15625, write their half-precision bits by hand, and check them with floatAsBinaryString or the linked visualizers. Aim to explain exponent bias aloud with one example.

Scope and limitations

The author calls it a simplified overview: it leaves out -0, infinities and NaN, and does not cover rounding or precision loss in arithmetic. The decoding walkthrough is an image, and the code is JavaScript.

Access and format

README on GitHub in the MIT-licensed trekhleb/javascript-algorithms repository; English, free to read. An interactive version is linked on the author's blog.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/math/binary-floating-point/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email