Find a course

Module 3: Hexadecimal and OctalLesson 6 of 1112 min

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.

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.

HexBinaryHexBinary
0000081000
1000191001
20010A1010
30011B1011
40100C1100
50101D1101
60110E1110
70111F1111

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

Binary to hex in one moveProcess diagram: 10110100 → 1011 | 0100 → B | 4 → 0xB4 = 180.101101001011 | 0100B | 40xB4 = 180

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).

  1. 11111111
  2. 00001010
  3. 10100101
  4. 01111111
  5. 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:

RedGreenBlue
HexFF8800
Decimal2551360

Full red, about half green and no blue: a bright orange.

Some landmarks make color codes readable at a glance:

  • #000000 is black (all off), and #FFFFFF is white (all full).
  • #FF0000 is pure red, #00FF00 pure green, #0000FF pure blue.
  • When all three pairs are equal, as in #808080, the color is a shade of gray.
  • Bigger numbers mean brighter: #330000 is a dark red, #FF6666 a 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.

The three channels of #1E90FFBar chart with 3 categories: Red (1E): 30; Green (90): 144; Blue (FF): 255.0100200Red (1E)Green (90)Blue (FF)30144255
The three channels of #1E90FF
ItemBrightness (0-255)
Red (1E)30
Green (90)144
Blue (FF)255

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:

Octal01234567
Binary000001010011100101110111

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

AspectBinaryOctalHex
Base2816
Bits per digit134
255 is written11111111377FF
Seen inHardware, logicUnix file permissionsColors, memory addresses

Step 12 of 12Practice · Choose one

What color is #00FF00?