To convert decimal to IEEE 754 floating point, encode the sign, binary significand, and biased exponent, then pack them into a 32-bit binary32 or 64-bit binary64 field. The result is a bit pattern rather than a decimal label, so the target format and the final consumer's byte order must both be known.

how to convert decimal to ieee 754 floating point
How to Convert Decimal to IEEE 754 Floating Point Bits

The fields that make up the bit pattern

The IEEE 754-2019 standard defines the interchange layouts used for binary32 and binary64. Both formats divide a value into a sign field, an exponent field, and a fraction field. Their field widths and exponent biases differ, which changes both the represented range and the amount of precision available.

Feature binary32 binary64
Total width 32 bits 64 bits
Sign field 1 bit 1 bit
Exponent field 8 bits 11 bits
Fraction field 23 bits 52 bits
Exponent bias 127 1023
Hexadecimal display 8 digits 16 digits

For a normal finite value, let s be the sign bit, E the stored exponent, F the integer represented by the fraction field, and f the number of fraction bits. Its value is calculated as (−1)^s × (1 + F / 2^f) × 2^(E − bias). The hidden leading 1 supplies one additional binary digit of precision for normal values.

A subnormal value has an all-zero exponent field and no hidden leading 1. Its fraction is scaled using an effective exponent of one minus the bias. Zero, infinity, and NaN use separate field combinations, so they must be recognized before applying the normal-value formula.

Build the bit pattern by hand

A manual conversion makes the rounding point visible. The same process can be applied to binary32 or binary64 by changing the field widths and bias.

  1. Choose the target format. Confirm whether the receiving language, file, protocol, or hardware requires binary32 single precision or binary64 double precision. Also follow its required rounding behavior.
  2. Separate the sign. Use 0 for a positive value and 1 for a negative value. A negative zero remains negative even though its numeric value is zero.
  3. Convert the absolute decimal magnitude to binary. Repeated division by two produces integer bits, while repeated multiplication by two produces fraction bits. A decimal fraction may require an infinite expansion, so stop after enough bits to apply the target format's precision.
  4. Normalize the binary value. For a normal nonzero value, rewrite it in the form 1.xxxxx × 2^e. Record the exponent e and retain the digits after the leading 1 for the fraction field.
  5. Round the significand. Keep up to 23 fraction bits for binary32 or 52 fraction bits for binary64, applying the required rounding rule. Padding with zeros is valid when the omitted bits are already zero.
  6. Encode the exponent. For a normal value, add the format bias to e, then write the result in the required exponent-field width. A subnormal uses an all-zero exponent field and a scaled fraction.
  7. Pack and format the result. Concatenate the sign, exponent, and fraction from most significant to least significant bit. Group the completed pattern into four-bit hexadecimal digits.

After the manual result is assembled, compare it with a browser-generated value. That comparison is especially useful for detecting an incorrect bias, a lost trailing bit, or a rounding mistake.

A complete binary32 conversion

Convert the decimal value -6.75 into a binary32 IEEE 754 pattern. This value is exactly representable in binary32.

  1. Encode the sign. Because the value is negative, the sign bit is 1.
  2. Convert the magnitude. The absolute decimal value 6.75 becomes 110.11 in binary. Normalizing it gives 1.1011 × 2^2.
  3. Calculate the exponent. The unbiased exponent is 2. Adding the binary32 bias of 127 produces a stored exponent of 129, which occupies eight bits as 10000001.
  4. Prepare the fraction. Remove the hidden leading 1 from 1.1011. The remaining fraction is 1011, followed by 19 zero bits to fill the 23-bit fraction field.
  5. Pack the fields. The grouped representation is 1 | 10000001 | 10110000000000000000000, producing the full bit pattern 11000000110110000000000000000000.
  6. Verify the value and hex. Substituting the fields into the normal-value formula gives (−1)^1 × 1.1011₂ × 2^(129 − 127) = -6.75. Grouping the bits into hexadecimal pairs gives C0B00000.

The resulting decimal and hexadecimal forms describe the same stored binary32 value. Because the source value was exactly representable, narrowing did not change it.

For a browser-based conversion that shows the value actually stored, use the IEEE 754 Floating Point Converter. It exposes binary32 and binary64 bit patterns locally in the browser and can also decode bits or hexadecimal patterns.

Convert a decimal value in the browser

  1. Choose decimal-to-bits mode. This is the direction that converts a base-ten value into an IEEE 754 field.
  2. Select binary32 or binary64. Choose the width required by the eventual consumer rather than selecting the format with the more convenient-looking decimal output.
  3. Enter one value. Decimal input accepts ordinary base-ten notation with an optional sign, fraction, and decimal exponent. It also accepts Infinity, -Infinity, and NaN. Hexadecimal numeric literals, expressions, commas, units, and locale-specific decimal separators are rejected, so clean the source value before entering it.
  4. Convert and inspect the result. Review the stored value together with its sign, exponent, fraction, classification, binary bits, hexadecimal representation, and unbiased exponent when applicable.
  5. Optionally decode the pattern. Switch to bits-or-hex-to-decimal and retain the same format. Decoding requires exactly 32 or 64 binary digits, or exactly 8 or 16 hexadecimal digits, with an optional 0x prefix for hexadecimal.
  6. Copy the hex and verify it against the consumer. The converter shows the most-significant byte first, with exactly eight digits for binary32 or 16 for binary64. Its copy action copies the hex digits without the 0x label. Check precision and byte order before using the value in a protocol or file.

Internally, the converter uses the browser's DataView API to write through setFloat32 or setFloat64 in big-endian order and then reads the stored value back. JavaScript first parses a decimal input as a binary64 Number, so binary32 exposes the additional rounding that occurs when that value is narrowed to single precision. Binary64 reflects the browser's double-precision interchange value, not the original decimal spelling or arbitrary-precision arithmetic. The ECMAScript Number type defines the numeric type used by JavaScript.

Check rounding, classifications, and edge values

Decimal-to-binary conversion is not proof that a decimal value is exact. Many decimal fractions have infinite binary expansions and must be rounded to a nearby representable value. Large integers can lose unit precision in binary64, and binary32 loses precision sooner. Use decimal or integer libraries when a domain requires exact money, identifiers, or arbitrary precision.

  • Zero and subnormal: An all-zero exponent with a zero fraction is classified as zero. An all-zero exponent with a nonzero fraction is subnormal. A nonzero exponent below the all-ones pattern represents a normal value.
  • Infinity and NaN: An all-ones exponent with a zero fraction represents infinity; an all-ones exponent with a nonzero fraction represents NaN. The converter reports their classification instead of assigning a misleading finite unbiased exponent.
  • Unbiased exponent: For normal values, subtract 127 in binary32 or 1023 in binary64. For subnormal values, the effective exponent is one minus the applicable bias.
  • Signed zero: Positive and negative zero have different sign bits even though they usually compare as equal. They can produce different results in operations such as reciprocals. The converter preserves -0 when it is entered or decoded.
  • NaN payloads: Decoding keeps the entered NaN bits visible, but JavaScript exposes NaN as a single numeric category. Distinct NaN payloads therefore cannot be distinguished through the numeric value alone.

Match the hexadecimal to the actual consumer

The hexadecimal output is a field representation, not automatic permission to paste it into any file or protocol. The converter uses big-endian DataView operations internally, but a downstream consumer may require a different byte order.

  • Confirm the width. A 32-bit consumer cannot safely consume the 16-digit binary64 form, and a 64-bit consumer expects a different field layout.
  • Confirm byte order. Hex is displayed most-significant byte first. If the receiving format expects little-endian bytes, the byte order must be adapted to that specification rather than inferred from the displayed hex.
  • Confirm precision and rounding. Check whether the consumer expects binary32 or binary64 and whether its conversion rules match the value shown by the tool.
  • Compare with the governing specification. Validate the pattern against the language, file format, network protocol, or hardware specification that will consume it. The IEEE standard defines the float fields; the surrounding specification determines how those fields are serialized and interpreted.

Use the converter's stored value and bits as the conversion result, then apply only the serialization rules explicitly required by the destination system.

If you're weighing options, IP to Decimal API Alternative for Strict IPv4 Values covers this in detail.