Stax
Tools

IEEE 754 Converter

Convert decimal numbers to IEEE 754 floating point representation.

0sign
10000000exponent (8 bits)
10010010000111111011011mantissa (23 bits)
Decimal
3.141593
Hex
0x40490FDB
Sign
0 (positive)
Exponent
128 (biased), 1 (actual)

IEEE 754コンバーターの仕組み

IEEE 754コンバーターは10進数を32ビット単精度および64ビット倍精度浮動小数点2進数表現に変換し、またその逆も行います。符号ビット・バイアス付き指数・仮数フィールドを色分けして個別に表示するため、コンピュータサイエンスの学生・レジスタ値をデバッグする組み込み開発者・浮動小数点演算で0.1 + 0.2 ≠ 0.3 になる理由を理解する必要がある人にとって価値ある教育ツールです。

IEEE 754単精度は1符号ビット・8指数ビット(バイアス127)・23仮数(有効数字)ビットを使用します。値は(−1)^符号 × 2^(指数−127) × 1.仮数で計算されます。例えば10進数5.75は符号=0・指数=10000001(2からバイアスされた129)・仮数=01110000000000000000000となり、32ビット16進数表現は0x40B80000になります。

IEEE 754は例外的な値のために特殊なビットパターンを予約しています。全ビットがゼロの指数と仮数がゼロの場合、正または負のゼロ(ゼロの2つの表現)を表します。全ビットが1(255)の指数と仮数がゼロの場合、±Infinityを表します。全ビットが1の指数と任意の非ゼロ仮数はNaN(非数)です。ゼロの指数と非ゼロ仮数を持つ非正規数は最小の正規浮動小数点よりも小さい値を表します。

倍精度(64ビット)は1符号ビット・11指数ビット(バイアス1023)・52仮数ビットを使用し、約15〜17桁の有効10進数桁を提供します。単精度は6〜9桁のみです。多くの金融・科学アプリケーションでは倍精度が必要で、組み込みシステムはメモリを節約してFPU倍精度サポートのないハードウェアの速度を向上させるために単精度をよく使用します。コンバーターは精度関連のバグを診断するために両フォーマットに対応しています。

Pythonでは、struct.pack('!f', 5.75)でfloatを4バイトのIEEE 754ビッグエンディアン表現にエンコードします。struct.unpack('!f', b'\x40\xb8\x00\x00')でデコードします。Cでは、floatとuint32_tのユニオンが浮動小数点表現へのビットレベルアクセスを提供し、直列化とレジスタ値の検証・操作に使用できます。コンバーターの16進数出力は両コンテキストで直接使用できます。

よくある質問

What is IEEE 754?
IEEE 754 is the international standard for floating-point arithmetic. It defines how decimal numbers are stored in binary using a sign bit, exponent bits, and a mantissa (fraction) field.
Why do floating point numbers have rounding errors?
Most decimal fractions cannot be represented exactly in binary. For example, 0.1 in binary is a repeating fraction like 0.0001100110011… truncated at the mantissa length, causing small rounding errors.
What is the difference between float and double?
A 32-bit float has 1 sign bit, 8 exponent bits, and 23 mantissa bits (~7 decimal digits precision). A 64-bit double has 1 sign bit, 11 exponent bits, and 52 mantissa bits (~15 decimal digits precision).

関連ツール