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.
…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.
- In base
b, the weight of thek-th digit from the right (starting at 0) isbto thek-th power. - In any base, you find the value by summing each digit × that digit's weight.
- The same "quantity" looks different depending on the base. For instance, "11111111 apples" and "255 apples" are the same quantity.
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.
- With only two states, it is hard to mistake
0for1even with some noise, and circuits can be made simple, fast, and cheap. - If you tried to handle decimal directly with ten voltage levels, a tiny voltage fluctuation could make a digit indistinguishable from its neighbor, sharply reducing reliability.
- For these reasons, the internal representation of a computer consistently uses binary. The decimal numbers and characters we see are a "facade" converted at the display stage.
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.
- One byte (8 bits) = two hexadecimal digits. For example,
11111111can be written compactly asFF. - Color codes: a web color
#RRGGBBrepresents red, green, and blue each as one byte (0–255), written as two hex digits apiece.#FF0000is red at the maximum (255) with green and blue at 0 — pure red. - Memory dumps and addresses: memory contents and addresses are conventionally shown in hexadecimal, because byte boundaries line up every two digits and it is easy for people to read.
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.
13 ÷ 2 = 6 remainder 16 ÷ 2 = 3 remainder 03 ÷ 2 = 1 remainder 11 ÷ 2 = 0 remainder 1
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.
- Group into fours from the right:
1111 | 1111. 1111=8+4+2+1 = 15=F.- Therefore
11111111 = FF. Conversely,FFexpands each digit into four bits to give back1111 1111.
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.
| Decimal | Binary (4 digits) | Hexadecimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
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).
- Because the width is fixed, a calculation that exceeds the maximum causes an overflow. With 8 bits,
255 + 1can overflow and wrap back around to0. - To represent negative numbers, most environments use a scheme called two's complement. The top bit takes on the role of a sign, so an 8-bit signed integer represents
-128 to 127.-1is represented in 8 bits as11111111. - The same bit pattern
11111111reads as255when treated as "unsigned" and as-1when treated as "signed (two's complement)." The key point is that a value is only determined once you decide which width to use and how to interpret it.
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.