The Hex-Binary Shortcut and Octal
Convert between hex and binary instantly using groups of four bits, read web color codes, and meet octal with its groups of three bits.
Welcome back!
Step 1 of 12Learn
Four bits, one hex digit
Here's why programmers love hex: 16 = 24, so each hex digit corresponds to exactly four bits, a nibble. That makes converting between hex and binary almost instant, no decimal required.
| Hex | Binary | Hex | Binary |
|---|---|---|---|
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | A | 1010 |
| 3 | 0011 | B | 1011 |
| 4 | 0100 | C | 1100 |
| 5 | 0101 | D | 1101 |
| 6 | 0110 | E | 1110 |
| 7 | 0111 | F | 1111 |
Hex to binary: replace each hex digit with its four bits.
0x3E → 3 is 0011, E is 1110 → 00111110.
Binary to hex: split the bits into groups of four starting from the right, padding the leftmost group with zeros if needed, then replace each group with its hex digit.
1011010 → split from the right: 101 and 1010 → pad: 0101 1010 → 5A.
Grouping from the left instead is the classic error: 1011 010 would give the wrong result. Always group from the right, just as you put commas in a big decimal number starting from the right.
With this shortcut, a 32-bit value like 11011110101011011011111011101111 becomes the much friendlier DEADBEEF, a famous hex value programmers use as a marker in memory.
Step 2 of 12Diagram
Binary to hex in one move
Tap a shape with to see more.
- 10110100
- 1011 | 0100
Split into nibbles from the right.
- B | 4
1011 = 11 = B, 0100 = 4.
- 0xB4 = 180
Step 3 of 12Practice · Work it out
Convert the binary number 11010111 to hex, then give the decimal value of the left hex digit.
Step 4 of 12Practice · Match the pairs
Match each byte in binary to its hex value.
Tap an answer, then tap the place where it belongs (or drag it there).
- 11111111
- 00001010
- 10100101
- 01111111
- 10000000
Step 5 of 12Learn
Reading web colors
Screens make colors by mixing red, green and blue light. Each of the three channels is usually stored in one byte, a value from 0 (none) to 255 (full brightness). That's 256 × 256 × 256 = 16,777,216 possible colors, often called 24-bit color.
A web color code like #FF8800 is simply those three bytes written in hex, two digits each:
| Red | Green | Blue | |
|---|---|---|---|
| Hex | FF | 88 | 00 |
| Decimal | 255 | 136 | 0 |
Full red, about half green and no blue: a bright orange.
Some landmarks make color codes readable at a glance:
#000000is black (all off), and#FFFFFFis white (all full).#FF0000is pure red,#00FF00pure green,#0000FFpure blue.- When all three pairs are equal, as in
#808080, the color is a shade of gray. - Bigger numbers mean brighter:
#330000is a dark red,#FF6666a light red.
Web designers also use a 3-digit short form, where each digit is doubled: #F80 means #FF8800. Once you understand hex, you can adjust colors by editing the numbers directly instead of hunting through a color picker.
Step 6 of 12Practice · Chart
The three channels of #1E90FF
Each pair of hex digits is one byte. Converting them shows how much of each light the color uses.
Tap the channel at full brightness.
Tap the bar that answers the question, then press Check.
Step 7 of 12Practice · Sort into groups
Sort these web colors by what they look like.
Tap an item, then tap its group (or drag it there).
Step 8 of 12Learn
Octal, base 8
Octal is base 8, using the digits 0 through 7, with places worth 1, 8, 64, 512. Since 8 = 23, each octal digit corresponds to exactly three bits:
| Octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| Binary | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
Converting works like hex, just with groups of three bits from the right. Binary 110101 splits into 110 and 101, which is octal 65. In decimal, that's 6 × 8 + 5 = 53.
Octal was popular on early computers whose word sizes were multiples of three bits. Today hex has mostly replaced it, but octal survives in one famous place: file permissions on Linux and macOS. A permission like 755 gives three groups of three bits for the owner, the group and everyone else, where the bits mean read (4), write (2) and execute (1). So 7 = 4 + 2 + 1 means read, write and execute, and 5 = 4 + 1 means read and execute. A command like chmod 755 script.sh sets exactly those permissions.
You'll also see octal in some programming languages, written with a 0o prefix, as in 0o755.
Step 9 of 12Note
Step 10 of 12Practice · Fill in the blanks
Fill in the blanks
One hexadecimal digit represents bits, and one octal digit represents bits.
Step 11 of 12Compare
Binary, octal and hex compared
| Aspect | Binary | Octal | Hex |
|---|---|---|---|
| Base | 2 | 8 | 16 |
| Bits per digit | 1 | 3 | 4 |
| 255 is written | 11111111 | 377 | FF |
| Seen in | Hardware, logic | Unix file permissions | Colors, memory addresses |
Step 12 of 12Practice · Choose one
What color is #00FF00?
Lesson complete!