BFloat16 Converter and Bit Inspector – Free

This bfloat16 converter encodes a decimal number into the 16-bit brain floating point format, or decodes a hex or binary pattern back to its value. Every field of the result is listed separately.

How to use the BFloat16 Converter tool

  1. Under Input format, choose Number to encode a decimal value, or Hexadecimal or binary bits to decode a stored bfloat16 word.
  2. Fill in Number or bit pattern, for example -13.25, C154 or 0b1100000101010100.
  3. Select Inspect bits. The Example button fills in -13.25 and runs the conversion for you.
  4. Read the Value, Hex, Bits, Sign, Exponent, Fraction and Class lines in the result, then select Copy.

What the bfloat16 format is

Bfloat16 packs a floating point number into 16 bits: 1 sign bit, 8 exponent bits with a bias of 127, and 7 fraction bits. The sign and exponent are the same as in IEEE 754 single precision. Only the fraction is shorter, 7 bits in place of 23. A bfloat16 word is therefore the upper half of the matching float32.

That design keeps the full float32 range, up to about 3.39e38, and gives up precision: 8 significant bits, or between 2 and 3 decimal digits. The format comes from machine learning hardware and is not part of IEEE 754. You find it in the AVX-512 BF16 and Arm BF16 instruction sets and as torch.bfloat16 and tf.bfloat16.

Worked example: -13.25 and 0.1 in bfloat16

-13.25 equals -1.65625 x 2^3. The exponent field is 3 + 127 = 130, or 10000010. The fraction 0.65625 is 1010100 in binary and fits in 7 bits, so the value is exact. The float32 pattern is C1540000, and the bfloat16 pattern is its first four digits, C154.

0.1 shows the rounding. Its float32 pattern is 3DCCCCCD. Cutting off the low half would give 3DCC, which is 0.099609375. This tool rounds to the nearest value and returns 3DCD, which is 0.10009765625.

Value: -13.25
Hex: 0xC154
Bits: 1100000101010100
Sign: 1
Exponent: 10000010
Fraction: 1010100
Class: normal

Rounding, overflow and special values

Number mode rounds the parsed value straight to the nearest bfloat16, with ties going to the even fraction. These cases show the edges.

  • 257 becomes 256 and 259 becomes 260, because above 256 the spacing between values is 2.
  • 1e40 is out of range and returns Infinity, 0x7F80. The largest finite pattern is 0x7F7F.
  • 1e-40 lands in the subnormal range and becomes 0x0001, about 9.18e-41.
  • NaN is encoded as 0x7FFF, and -0 keeps its sign as 0x8000.
  • In bit mode, any pattern with an all-ones exponent and a nonzero fraction, such as 7FC0, is classed as NaN.

Input the converter accepts and rejects

Number mode takes ordinary decimal notation: an optional sign, digits, a decimal point and an exponent such as 1e-3. The words inf, infinity and nan work in any letter case. Hex floats, digit separators and commas are refused with the message Enter a number, Infinity or NaN.

Bit mode takes up to 4 hex digits with an optional 0x, or up to 16 binary digits after 0b. Spaces are ignored and short input is padded with leading zeros. A full float32 word such as C1540000 is too long and returns an error. Hex that starts with 0b followed by only 0s and 1s is read as binary, so write 0x0B10 to force hex.

Frequently asked questions

What is the difference between bfloat16 and FP16?

Both use 16 bits. Bfloat16 has 8 exponent and 7 fraction bits, so it spans the float32 range with coarse steps. IEEE half precision has 5 exponent and 10 fraction bits, so it is finer but tops out at 65504. The pattern C154 is -13.25 as bfloat16 and -2.6640625 as FP16.

How many decimal digits of precision does bfloat16 have?

About 2.4. The significand holds 8 bits, so every integer up to 256 is exact and 257 already rounds to 256. Treat the third significant digit of any bfloat16 value as approximate.

How do I convert a float32 to bfloat16 by hand?

Keep the upper 16 bits of the float32 word and use the lower 16 bits to decide rounding. If they are above 8000 hex, add one to the kept half. If they equal 8000 exactly, round to the even result.

What are the largest and smallest bfloat16 values?

The largest finite value is 0x7F7F, about 3.39e38. The smallest positive normal value is 0x0080, about 1.18e-38, the same as float32. Below that, subnormals go down to 0x0001, about 9.18e-41.

Related tools