Binary and Hexadecimal Explained — How Computers Represent Numbers

We normally count in decimal (base 10), but inside a computer everything runs in binary (0 and 1). And hexadecimal is simply a notation that groups that binary into a form people can read and write more easily. This article first nails down the shared idea of "positional notation," then covers how binary and hexadecimal (and octal) work, the concrete steps for converting between them, and worked examples such as 255 = 11111111 = FF, checking the arithmetic as we go.

The bottom line first: every numeral system can be explained by a single idea — place value. Binary just lines up weights of …8 4 2 1, while hexadecimal lines up …256 16 1. Computers use binary because the two states 0 and 1 can be reliably distinguished by circuits, and we use hexadecimal because one digit is exactly four bits, mapping neatly onto binary.

1. Positional notation — it all comes down to place value

The reason 253 in decimal means "253" is that each digit has a weight. From the right, the weights are 1 (10 to the 0th power), 10 (10 to the 1st), 100 (10 to the 2nd), and so on — each step to the left multiplies the weight by 10.

Example: 253 = 2×100 + 5×10 + 3×1 = 200 + 50 + 3

This "how many times larger each step is" is called the base (radix). The base of decimal is 10, binary is 2, hexadecimal is 16, and octal is 8. The number of symbols used equals the base: decimal uses the 10 symbols 0–9, binary uses just 0 and 1.

2. Binary — 0 and 1, bits, and why computers use binary

Binary has base 2 and uses just two symbols, 0 and 1. The place weights grow by a factor of 2 from the right: 1, 2, 4, 8, 16, 32, 64, 128…. A single binary digit is called a bit, and eight bits grouped together form a byte.

Example: converting the binary number 1101 to decimal:

1101 = 1×8 + 1×4 + 0×2 + 1×1 = 8 + 4 + 0 + 1 = 13

Why computers use binary

The inside of a computer is countless electronic circuits. The circuit elements (transistors) are good at distinguishing two stable states: "voltage high vs. low" or "current flowing vs. not." By mapping these two states to 1 and 0, you can represent numbers, characters, and instructions alike.

3. Hexadecimal — 0–9 and A–F, 1 digit = 4 bits

Hexadecimal has base 16 and represents 0–15 with a single digit. Since there are no numerals for 10–15, we use the letters A (=10), B (=11), C (=12), D (=13), E (=14), and F (=15). The place weights grow by a factor of 16 from the right: 1, 16, 256, 4096….

Example: converting the hexadecimal number 2F to decimal:

2F = 2×16 + F×1 = 2×16 + 15×1 = 32 + 15 = 47

Why hexadecimal is convenient — color codes and memory displays

Because 16 is 2 to the 4th power, one hexadecimal digit corresponds exactly to four binary digits (four bits). This group of four bits is called a nibble. So by simply splitting binary into groups of four digits and replacing each with a hex digit, you can write a long string of 0s and 1s at a quarter of the length.

4. A quick word on octal

Octal has base 8 and uses the digits 0–7. Since 8 is 2 to the 3rd power, one octal digit corresponds to three binary digits. It was once widely used where groups of three bits were convenient, and you still see it today in Unix/Linux file permissions (such as chmod 755).

Example: the octal number 17 in decimal is 1×8 + 7×1 = 8 + 7 = 15. In modern programming, however, four-bit hexadecimal is more common, and octal has limited use.

5. Conversion methods — working it out by hand

Conversions between bases can be done reliably with a few fixed procedures. Let us go through the main ones, always checking the arithmetic.

Decimal → binary (repeated division)

Divide the decimal number by 2 and record the remainder, repeating until the quotient becomes 0. Reading the remainders from bottom to top gives the binary number. Example: 13 to binary.

Reading the remainders from the bottom gives 1101. Check: 8+4+0+1 = 13 — it matches.

Binary → decimal (multiply by the weights)

Just multiply each bit by its place weight (…8 4 2 1) and add. Example: 1101 = 8 + 4 + 0 + 1 = 13. This is the inverse of the division above.

Binary ↔ hexadecimal (group four digits at a time)

This is where hexadecimal shines. Split the binary into groups of four digits from the right and replace each group with one hex digit (pad the left with 0 if needed). Example: 11111111 to hexadecimal.

Pulling it together with an example: the same quantity "255" looks like this in different bases:
decimal 255 = binary 11111111 = hexadecimal FF = octal 377.
Check: binary 11111111 = 128+64+32+16+8+4+2+1 = 255. Hexadecimal FF = 15×16 + 15 = 255. Octal 377 = 3×64 + 7×8 + 7 = 192+56+7 = 255. They all equal 255.

Listing the correspondence for 0–15 makes the binary–hexadecimal relationship (4 bits = 1 digit) easy to see.

DecimalBinary (4 digits)Hexadecimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

6. Negative numbers and bit width — one step deeper

So far we have only handled non-negative integers. In a real computer, the size of the "box" that holds a value — the bit width — is fixed in advance: 8, 16, 32, 64 bits, and so on. With 8 bits you can represent the 256 patterns 0–255 (2 to the 8th power).

Two's complement and floating point (how fractions are represented) are deep enough to each be a topic of their own, so here it is enough to grasp that "the meaning changes depending on the bit width and interpretation."

Free Tool Convert for real with the Base Converter Convert among decimal, binary, hexadecimal, and octal. You can type in the examples from this article (255 = 11111111 = FF = 377) and check them on the spot.

Frequently Asked Questions (FAQ)

Why do computers use binary?

Because the basic components of a computer, such as transistors and memory cells, are good at reliably distinguishing two stable states, like "voltage high vs. low" or "current flowing vs. not flowing." With only two states, even in the presence of slight noise it is hard to mistake 0 for 1, and the circuits can be made simple, fast, and cheap. Distinguishing two levels is far more reliable than accurately distinguishing ten voltage levels, so binary is used for the internal representation.

Why is hexadecimal used?

Because one hexadecimal digit corresponds exactly to four bits (four binary digits), making it easy to convert to and from binary. Long, hard-to-read binary strings can be written compactly by grouping them four digits at a time. For example, eight bits (one byte) can be written as two hexadecimal digits. It is widely used as a human-friendly notation in memory dumps, color codes (#RRGGBB), character codes, MAC addresses, and more.

Why does 255 become FF in hexadecimal?

In hexadecimal a single digit represents 0 to 15, and F means 15. In FF, the upper digit is 15x16 = 240 and the lower digit is 15, so together they make 240 + 15 = 255. 255 is the maximum value that fits in eight bits (11111111 in binary), which coincides exactly with FF, the largest two-digit hexadecimal value. This is why one byte equals two hexadecimal digits, and why 255 appears as FF in color codes and the like.

← Back to the Tech Blog list