什麼是 IEEE 754 轉換器?
IEEE 754 轉換器顯示電腦如何儲存浮點數。輸入像 3.14159 這樣的十進位值,工具將其編碼為 IEEE 754 標準定義的精確位元模式,將結果分為三個部分:符號位元、指數欄位和尾數(也稱為分數或尾數)。它雙向工作,因此您也可以貼上 32 位元或 64 位元二進位字串或其十六進位等效字串,並將其解碼回它所代表的數字。
用作 IEEE 754 浮點轉換器,它使經典的 0.1 問題可見。選擇單(32 位元),保留十進位,輸入0.1 並按一下轉換:十六進位為3DCCCCCD,偏置指數為123(無偏置2^-4),儲存值為0.10000000149011612。切換到雙(64 位元)且相同的輸入給出 3FB999999999999999A,但儲存值顯示為 0.1,因為雙列印為讀回相同 64 位元的最短十進位。
浮點數不是按照我們書寫的方式儲存的。依照 IEEE 754-2019 中的方案,值被保留為符號、二的冪和小數有效數。這種設計就是為什麼 0.1 加 0.2 不完全等於 0.3,為什麼儲存時有些小數會四捨五入,以及為什麼在相同的 32 或 64 位元中可能存在非常大和非常小的幅度。看到所佈置的符號、指數和尾數使這些行為具體而不是神秘,這在您調試數字錯誤、編寫序列化器、研究電腦體系結構或比較單精度和雙精度時很有幫助。
該工具運行客戶端,並使用與 JavaScript 引擎內部使用的相同的 ArrayBuffer 和 DataView 原語,因此位元模式與 CPU 將產生的內容相匹配,直至舍入。單精度(二進位32)使用1個符號位元、8個指數位元和23個尾數位元;雙精度(binary64)使用1個符號位元、11個指數位元和52個尾數位元。特殊情況也得到處理:正負零、次正規數、無窮大和NaN都被識別。您輸入的任何內容都不會上傳,並且工具在載入後仍保持離線工作。
如何使用 IEEE 754 轉換器?
選擇單精度或雙精度
選擇單(32 位元、二進位 32)或雙(64 位元、二進位 64)。 Double 是大多數語言的預設值,因此請選擇它,除非您專門針對 float。
選擇您的輸入類型
選擇十進制對數字進行編碼,或選擇六進制或二進制將現有位元模式解碼回值。十進制模式接受 Infinity、-Infinity 和 NaN 等特殊輸入。
輸入您的值
輸入十進制數字,例如 3.14159 或 6.022e23,或貼上精度所需的十六進位數字或位元的精確數量。轉換後,轉換會立即更新。
閱讀分解並複製
查看符號、指數和尾數,以及完整位元、十六進位、有偏和無偏指數,以及從位元讀回的儲存值。表的每一行都有自己的複製按鈕。
Single and double precision, side by side
A float is three fields packed into a fixed number of bits: one sign bit, an exponent, and the mantissa that holds the digits. How many bits each field gets is the entire difference between a 32-bit and a 64-bit number, and it is what decides where precision runs out.
| Field | Single (32-bit) | Double (64-bit) |
|---|---|---|
| Sign | 1 bit | 1 bit |
| Exponent | 8 bits | 11 bits |
| Mantissa | 23 bits | 52 bits |
| Exponent bias | 127 | 1023 |
| Total | 4 bytes | 8 bytes |
主要特點
單精度和雙精度
轉換為二進位 32(1 + 8 + 23 位元)或二進位 64(1 + 11 + 52 位元),這兩種格式在幾乎所有語言中都使用 float 和 double。
兩個方向
將十進制數編碼為位,或將二進位或十六進位位元模式解碼回其表示的值,無需切換工具。
符號、指數、尾數分裂
結果分為三個字段,偏置指數儲存在位元中,並且它應用無偏二次方。
檢測到特殊值
正零和負零、次正規數、無窮大和 NaN 都被識別,因此您可以準確地看到位元模式屬於哪種情況。
Frequently Asked Questions
Related Tools
ASCII Table
Full ASCII and extended Latin-1 table with decimal, hex, octal, binary, HTML entity, and character name for every code 0–255, plus a text-to-ASCII-code encoder.
Binary Calculator
Add, subtract, multiply, and divide binary numbers, or run AND, OR, XOR, NOT, and bit shifts, with every result shown in binary, octal, decimal, and hex. 100% client-side.
Binary Translator
Translate text to binary and binary to text, plus hexadecimal, decimal, and octal, with full UTF-8 support
Morse Code Translator
Translate text to Morse code and Morse code to text using the International (ITU) standard, with audio playback and full punctuation support
Comments
0 comments
No comments yet. Be the first to share your thoughts!