keepcalculator

06 Numbers and Powers

Convert Number to 8-Bit Floating Point

Card No. 06·0426 · Updated · Standard formula, shown below

8-bit pattern (E sign fraction) 1 bits
Decoded value (format-dependent)
1.000000 value
Result
Number to convert
1
You entered
8-bit format
E4M3
You entered
You enter
Number to convert, 8-bit format
You get
8-bit pattern (E sign fraction), Decoded value (format-dependent)
Rounding
0 dp · 6 dp

An 8-bit floating-point calculator converts a decimal number into a compact 8-bit floating-point bit pattern and shows the value that pattern represents. Enter a number and choose the exponent and fraction-bit layout, because “8-bit float” has no single universal format.

Formula

The block above is a conceptual input-and-output specification: it displays the entered number, but its expressions do not perform binary encoding. A true conversion needs format-specific rounding, exponent bias, bit packing, and special-value rules. Those operations cannot be represented faithfully by the calculator block’s permitted arithmetic expressions, so the displayed “pattern” and “decoded value” are placeholders, not valid conversion results. Do not rely on them to encode data.

For a normalized binary floating-point number, the general value is:

value = (−1)s × (1 + fraction) × 2e − bias

  • s is the one-bit sign: 0 for positive and 1 for negative.
  • e is the unsigned exponent field interpreted as an integer.
  • bias is the format’s exponent offset.
  • fraction is the binary fraction encoded by the fraction field; with m fraction bits its value is an integer from 0 through 2m−1 divided by 2m.

This equation describes normal values only. Zero, subnormal values, infinities, and NaNs have format-specific encodings. The selected labels E4M3 and E5M2 indicate four exponent bits plus three fraction bits, or five exponent bits plus two fraction bits, respectively; they do not by themselves specify every convention needed for a complete implementation.

Worked Example

The default inputs are x = 1 and format E4M3. The block returns 1 for both of its output expressions because each expression simply repeats x. That is not an encoded bit pattern. It would be misleading to present a bit string as the calculator’s answer without implementing and naming a precise format, including its rounding and special-value rules.

For comparison, under a common illustrative scheme with one sign bit, four exponent bits, three fraction bits, and bias 7, the value 1 is exactly representable as sign 0, exponent field 0111, fraction 000: 00111000. This example assumes ordinary normalized-number encoding and does not establish that every E4M3 implementation uses those rules. A real converter should show its format definition and decode its output using the same definition.

What “8-Bit Float” Means

A floating-point format divides its limited bits between sign, exponent, and significand (often called the mantissa, though the significand includes an implicit leading bit for normalized values). The exponent controls scale; the fraction controls precision. With only eight bits, there are few available patterns, so many decimal numbers must be rounded to a nearby representable value.

Unlike an 8-bit integer, an 8-bit float does not simply represent every whole number from 0 to 255. It can represent values across a range of magnitudes, but the spacing between representable values grows as the magnitude grows. Its exact range and precision depend on how the bits and special cases are assigned.

Commonly discussed layouts include E4M3 and E5M2, but names alone are not enough to guarantee identical behavior. Implementations can differ in exponent bias, treatment of the largest exponent, subnormal support, NaN encodings, and rounding. Always identify the precise specification or software format when exchanging bit patterns.

How to Convert a Number

A manual conversion follows a sequence, but the details change with the chosen format and rounding rule:

  1. Choose the exact 8-bit format, including exponent and fraction widths, bias, special-value conventions, and rounding mode.
  2. Record the sign. Convert the absolute value to binary, then express it in normalized form, such as 1.101 × 2³.
  3. Encode the exponent by adding the format’s bias. Check whether the result is reserved for a special value or outside the normal range.
  4. Keep the available fraction bits and round any discarded bits according to the format’s rule. Rounding can carry into the exponent.
  5. Pack sign, exponent, and fraction in the specified bit order. Decode the bit pattern independently to check the represented value.

Numbers too small for a normal exponent may become subnormal, round to zero, or follow another format-specific rule. Numbers too large may become infinity, saturate, or trigger an overflow condition, depending on the format.

When to Use a Converter and What to Check

An 8-bit float converter is useful when inspecting low-precision data, learning how floating-point fields work, or checking how a particular computing format rounds a value. Before trusting a result, make sure the tool states the exact format and offers both directions: decimal-to-bits and bits-to-decimal. A useful converter also identifies rounding behavior and how it handles zero, subnormals, overflow, infinity, and NaN.

  • Confirm the layout: E4M3 and E5M2 allocate precision and exponent range differently.
  • Check rounding: truncation and round-to-nearest can produce different bit patterns.
  • Inspect edge cases: values near zero, powers-of-two boundaries, and the largest finite value are revealing tests.
  • Keep the original value: conversion is generally lossy; converting back may not recover the input.

Do not confuse a bit pattern with a decimal number’s ordinary binary notation. For example, the eight bits in a floating-point encoding are fields interpreted together; reading them as an unsigned integer gives a different quantity.

Precision, Range, and Common Mistakes

Eight bits impose a strong trade-off. More exponent bits generally allow a wider range of magnitudes, while more fraction bits generally allow finer spacing and better precision within that range. No 8-bit layout can provide both the range and precision of a wider floating-point type.

A frequent mistake is to assume that every decimal input has an exact 8-bit representation. Most do not. The converter must select a nearby value, and the difference is quantization error. Another mistake is to treat all 8-bit floating-point formats as interchangeable: identical-looking fields can decode differently under different rules.

Also distinguish precision from range. Precision describes how closely nearby values can be represented; range describes the smallest and largest representable magnitudes. A format may cover a broad range while representing values coarsely, or provide finer precision over a narrower range.

Frequently Asked Questions

How do I convert a decimal number to an 8-bit float?
Choose a fully specified 8-bit format, then encode the sign, biased exponent, and rounded fraction according to its rules. A converter must state those rules to give a dependable bit pattern.

Is there one standard 8-bit floating-point format?
No. Several layouts and conventions exist. The label “8-bit float” alone does not uniquely determine exponent bias, special values, or rounding behavior.

Can every decimal number be represented exactly?
No. Eight bits provide only a limited set of values. Most decimal inputs are rounded to a nearby representable number, so converting back may produce a different decimal.

What is the difference between E4M3 and E5M2?
E4M3 allocates four bits to the exponent and three to the fraction; E5M2 allocates five and two. The trade-off affects range and precision, while exact behavior still depends on the format’s other rules.

Why does my 8-bit conversion differ between tools?
The tools may use different format specifications, rounding modes, overflow handling, or interpretations of special values. Compare those settings before comparing their bit strings.

Related

Formula used
in x | Number to convert | - | 1 | -
sel fmt | 8-bit format | E4M3=1, E5M2=2
out bits | 8-bit pattern (E sign fraction) | bits | x | 0
out back | Decoded value (format-dependent) | value | x | 6

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →