Hex to Decimal Converter: Binary, Two's Complement and IEEE 754
To convert hex to decimal, each digit is worth sixteen times the next: 0x1F = 1 × 16 + 15 = 31. The converter reads hex, decimal, binary, octal, text or a real number and shows it in 8 to 64 bits: unsigned, signed two's complement, big- and little-endian bytes, Q format and IEEE 754 floats with the exact stored value. The default 0x40490FDB is 1078530011, which is π in binary32 (3.1415927).
1078530011
0x40490FDB in 32 bits, unsigned
Integers are exact at every width up to 64 bits (BigInt). Floats round to nearest, ties to even, from the exact decimal you type, so binary16 and bfloat16 never double-round through binary64. The exact stored value is the dyadic rational the bits encode. Byte order applies to whole bytes; a 12-bit word is padded on the left.
Registers, frames and number formats are settled between hardware and firmware. We design both, from sensor drivers to radio protocols. Let's talk about your project in a free 30-minute audit.
IEEE 754 formats and bfloat16
Exponent bits set the range, fraction bits the precision. bfloat16 spans the same range as binary32 with a little over two decimal digits, enough for neural-network weights; binary16 is more precise but tops out at 65504.
| Format | Bits (sign · exponent · fraction) | Bias | Max finite | Min normal | Decimal digits |
|---|---|---|---|---|---|
| binary16 (half) | 16 (1 · 5 · 10) | 15 | 65504 | 6.1035e-5 | 3.31 |
| bfloat16 | 16 (1 · 8 · 7) | 127 | 3.3895e38 | 1.1755e-38 | 2.41 |
| binary32 (float) | 32 (1 · 8 · 23) | 127 | 3.4028e38 | 1.1755e-38 | 7.22 |
| binary64 (double) | 64 (1 · 11 · 52) | 1023 | 1.7977e308 | 2.2251e-308 | 15.95 |
Integer range by width
An unsigned w-bit integer runs from 0 to 2^w − 1; in two's complement, from −2^(w−1) to 2^(w−1) − 1. The 12 and 24-bit widths are those of common analog-to-digital converters.
| Bits | Signed min | Signed max | Unsigned max |
|---|---|---|---|
| 8 | −128 | 127 | 255 |
| 12 | −2048 | 2047 | 4095 |
| 16 | −32768 | 32767 | 65535 |
| 24 | −8388608 | 8388607 | 16777215 |
| 32 | −2147483648 | 2147483647 | 4294967295 |
| 64 | −9223372036854775808 | 9223372036854775807 | 18446744073709551615 |
Example encodings
The same values in the four formats. At 16 bits, 0.1 and π keep only three or four significant digits.
| Value | binary16 | bfloat16 | binary32 | binary64 |
|---|---|---|---|---|
| 1 | 0x3C00 | 0x3F80 | 0x3F800000 | 0x3FF0000000000000 |
| 0.1 | 0x2E66 | 0x3DCD | 0x3DCCCCCD | 0x3FB999999999999A |
| −2 | 0xC000 | 0xC000 | 0xC0000000 | 0xC000000000000000 |
| π | 0x4248 | 0x4049 | 0x40490FDB | 0x400921FB54442D18 |
FAQ
- How do you convert hex to decimal?
- Multiply each digit by the power of 16 of its position, starting from the right: 0x2A = 2 × 16 + 10 = 42, and 0xFF = 15 × 16 + 15 = 255. Letters A to F stand for 10 to 15. One hex digit is exactly 4 bits, which is why hex reads straight into binary: 0x2A = 0010 1010. The converter works at any width up to 64 bits with no loss, using BigInt integers.
- How does two's complement work?
- In w bits, a pattern whose top bit is 1 stands for its unsigned value minus 2^w. In 8 bits, 0xFF is −1 and 0x80 is −128; the range runs from −128 to 127. To negate x, invert every bit and add 1. According to Wikipedia it is the most common way computers represent signed integers, and the C23 standard requires it.
- How do I read a signed 24-bit ADC value?
- Pick 24 bits and Signed: 0xFFFFFE reads −2, 0x800000 reads −8388608. To store the reading in an int32_t, sign-extend it by copying bit 23 into bits 24 to 31, so 0xFFFFFE becomes 0xFFFFFFFE. Forgetting it gives 16777214 instead of −2, a classic trap with delta-sigma ADCs such as load-cell front ends.
- How is an IEEE 754 float encoded?
- A binary32 holds 1 sign bit, 8 exponent bits biased by 127 and 23 fraction bits, with an implicit leading 1 for normal numbers. 1.0 is 0x3F800000 and 0.1 is 0x3DCCCCCD. IEEE 754-2019 also defines binary16 and binary64; bfloat16, used in machine learning, keeps binary32's 8-bit exponent with only 7 fraction bits.
- Why is 0.1 not exact in floating point?
- 0.1 has no finite binary expansion, just as 1/3 has none in decimal. The nearest binary64 value is exactly 0.1000000000000000055511151231257827021181583404541015625; in binary32 it is 0.100000001490116119384765625, an error of 1.49 × 10⁻⁹. The converter shows this exact stored value, the rounding error and the spacing to the next float (ulp).
- What does Q15 mean?
- A fixed-point Qm.n number is an integer divided by 2^n. Q15 is 16 signed bits with 15 fractional bits: it spans −1 to 0.99997 in steps of 2⁻¹⁵, 0x4000 is 0.5 and 0x8000 is −1. According to Wikipedia, TI notation counts m without the sign bit (Q0.15) while ARM notation includes it (Q1.15). It is the format of DSP code and filters on microcontrollers without an FPU.
An electronics design house based in Montpellier, France, AESTECHNO brings 10+ years of design experience and a 100% success rate on CE/FCC certifications, across dozens of campaigns run over more than 10 years of practice. Encodings follow IEEE 754-2019, checked against Wikipedia's tables.