Hex vs. Decimal vs. Binary
Hex vs. Decimal vs. Binary
Understanding how to move between these three bases is critical for anyone auditing raw Bitcoin data. While the "Value" remains the same, the representation changes how we interact with the data.
1. Visualizing the Conversion
Let's look at the value 255 (the maximum value of a single byte).
| Base | Representation | Length | Context |
|---|---|---|---|
| Binary | 11111111 |
8 | Hardware Level |
| Decimal | 255 |
3 | Human Counting |
| Hex | FF |
2 | Coding/Debugging |
2. Converting Binary to Hex
To convert binary to hex, simply group the bits into sets of 4:
-
Binary:
1010 1011 -
Step 1:
1010= 10 in decimal = A in hex. -
Step 2:
1011= 11 in decimal = B in hex. -
Result:
AB
3. The "Power of 2" Alignment
Computers operate on bytes (8 bits).
-
Decimal is not aligned to bits. 100 in decimal is
01100100in binary. There is no simple way to see the "Bytes" inside a decimal number. -
Hex is perfectly aligned. Every two characters is exactly one byte.
DEADBEEF$\rightarrow$ 4 bytes (DE,AD,BE,EF).
4. Range Comparison
When looking at Bitcoin's Difficulty Target, we often deal with massive numbers.
-
A 32-bit Integer: Max value is $2^{32} - 1$ (4.2 billion). In hex, this is exactly
FFFFFFFF. -
A 256-bit Hash: In hex, this is 64 characters. In decimal, this is a number with 77 digits.
5. Security Context
When you see a private key in "Raw" format, you are looking at a 64-character hex string. If you lose even one character, or mistake an A for an 8, the value changes completely, and you lose access to your funds. This is why we use checksum-encoded formats like WIF or Base58 instead of raw hex for human use.
In the next section, we will analyze the confusing world of Little Endian vs. Big Endian.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: