Binary, Decimal, and Hex Conversions 101
September 2, 2026 • 5 min read

Table of contents
Computers store everything as bits, but humans think in decimal and write shorthand in hexadecimal. The good news: decimal, binary, and hexadecimal are just three spellings of the same value.
This is the practical companion to Information Representation Explained. No theory of signed integers or floats here, just how to read and convert numbers confidently.
Bits and bytes first
Before bases, you need two words:
- Bit: one binary digit,
0or1(off or on). It is the smallest unit of information. - Byte: a set of 8 bits. It is the smallest addressable memory unit on modern computers, when you read 1 byte from memory, you always get 8 bits together.
With n bits you get 2^n values, so one byte gives 2^8 = 256 values (0-255). Half a byte (4 bits) is called a nibble, which matters for hex later.
The three bases in 30 seconds
-
Decimal (base 10): digits
0-9. Human-readable. Positions are(..., 10^2, 10^1, 10^0)or(..., 100, 10, 1).342 = 3×100 + 4×10 + 2×1 -
Binary (base 2): digits
0-1. Machine-readable, this is what hardware stores. Positions are(..., 2^2, 2^1, 2^0)or(..., 4, 2, 1).101 = (right to left) 1×1 + 0×2 + 1×4 = 5 -
Hexadecimal (base 16): digits
0-9plusA-Ffor values 10-15. Binary shorthand. Positions are(..., 16^2, 16^1, 16^0)or(..., 256, 16, 1). One hex digit equals exactly 4 bits (a nibble, half a byte).0x8DA = 8×256 + 13(D)×16 + 10(A)×1 = 2048 + 208 + 10 = 2266
1. Binary → decimal: add the weights
Read right to left with weights ..., 256, 128, 64, 32, 16, 8, 4, 2, 1. Use as many as you need, 8 bits is just common because it is 1 byte, numbers can be larger.
Multiply each bit by its weight and add, going right to left so the math flows from 1 upward:
0011 0100 = 0*1 + 0*2 + 1*4 + 0*8 + 1*16 + 1*32 + 0*64 + 0*128
= 4+16+32 = 52
Same with the running example:
11010100 = 0*1 + 0*2 + 1*4 + 0*8 + 1*16 + 0*32 + 1*64 + 1*128
= 4+16+64+128 = 212
So 0b11010100 = 212. Zeros add nothing, you can skip them once it clicks.
Quick check: 0b1011 = 1*1 + 1*2 + 0*4 + 1*8 = 1+2+8 = 11.
2. Decimal → binary: subtract the biggest weight that fits
Go left to right through the weights. If the weight fits, write 1 and subtract it. If not, write 0. Example with 212:
212 - 128 = 84 -> 1
84 - 64 = 20 -> 1
20 - 32 = no -> 0
20 - 16 = 4 -> 1
4 - 8 = no -> 0
4 - 4 = 0 -> 1
0 - 2 = no -> 0
0 - 1 = no -> 0
result: 11010100
Another one, 13:
13 - 8 = 5 -> 1 (skip 128,64,32,16)
5 - 4 = 1 -> 1
1 - 2 = no -> 0
1 - 1 = 0 -> 1
result: 1101 (or 00001101 as a full byte)
Pad with leading zeros to fill a full byte when you want: 13 = 00001101.
3. Binary → hex: group by 4, then add
One hex digit = 4 bits with weights 8 4 2 1. Add the weights, write 10-15 as A-F. No table to memorize.
Split the bits into groups of 4 from the right, then calculate each group by hand:
binary 1110 0011 to hexadecimal:
1110 = 0*1 + 1*2 + 1*4 + 1*8 = 2+4+8 = 14 = E
0011 = 1*1 + 1*2 + 0*4 + 0*8 = 1+2 = 3
result = 0xE3
Same idea with the running example: 1101 = 1*1 + 0*2 + 1*4 + 1*8 = 1+4+8 = 13 = D, 0100 = 0*1 + 0*2 + 1*4 + 0*8 = 4, so 11010100 -> 0xD4.
Pad the left with zeros if the length is not a multiple of 4:
0b10111 -> 0001 0111 -> 0x17
0b11111111 -> 1111 1111 -> 0xFF (255)
That is why hex is popular: 0xFF is much easier to read than 11111111.
4. Hex → binary: calculate each digit to 4 bits
Do the reverse. For each hex digit, subtract the biggest weight that fits (8, 4, 2, 1) and pad with zeros to 4 bits:
hexadecimal 0x3F to binary:
3 =
3 - 2 = 1 -> 1
1 - 1 = 0 -> 1
0011 (pad left with 00 to make the nibble)
F (15) =
15 - 8 = 7 -> 1
7 - 4 = 3 -> 1
3 - 2 = 1 -> 1
1 - 1 = 0 -> 1
1111
result = 00111111
More, same mechanics:
0xD4 -> D (13) = 8+4+0+1 = 1101, 4 = 0100 -> 11010100
0x2F -> 2 = 0010, F = 1111 -> 00101111 (47 in decimal)
Color codes work the same way: #FF5733 is three bytes 0xFF 0x57 0x33, meaning red=255, green=87, blue=51.
For longer hex, stick to the binary middle step, it’s less error-prone.
Quick full loop
255 -> 11111111 -> 1111 1111 -> 0xFF
and back:
0xFF -> 11111111 -> 1+2+4+8+16+32+64+128 = 255.
Common beginner mistakes:
- Reading
0x10as ten. It is16(1×16 + 0). - Forgetting to group from the right.
0b10111is0x17, not0xB7. - Trying to convert long hex to decimal directly. Expand to binary first (direct weights are fine only for 1-2 digits).
Once this feels easy, go back to Information Representation Explained to see how the same bits become signed integers, floats, text, and files.
/sponsor
Enjoyed this post? You can sponsor me and this site.