Skip to content
Crayon CS

Make it comfy

Lesson style

Quick mode shows the key picture, a summary and the practice. Good for a refresher.

Theme
Font

Both fonts are designed to be easy to read. Some readers with dyslexia prefer Lexend.

Text size
Spacing
Animations

Lesson 4 of 7 · about 10 min

Hexadecimal and byte sizes

Long rows of 0s and 1s are hard to read, so programmers write each group of 4 bits as one hexadecimal digit (0–9, then A–F). And bytes add up into KB, MB and GB.

🧭 What you need first: Turning letters into numbers

The story

Read this out loud: 0100101011111010. Now try: 4AFA. Same number, but one of them you could read over the phone without losing your place.

That’s why programmers love hexadecimal. It’s not a different kind of data; it’s shorthand for binary. Chop the bits into groups of 4, and write each group as one symbol. Since 4 bits make 16 patterns, you need 16 symbols: 0 to 9, and then A, B, C, D, E, F for 10 to 15.

Another way: phone numbers in chunks

Nobody reads a phone number as 5551234567. You say “555, 123, 4567.” Grouping makes long numbers manageable. Hex is grouping bits by 4, and naming each group with one character.

Another way: egg cartons

Imagine counting eggs in cartons of 16 instead of 10. “2 cartons and 10 eggs” is 2 × 16 + 10 = 42. In hex you’d write that as 2A: 2 cartons, and A (ten) loose eggs.

Play with it

One byte, two hex digits

Flip the bits. Each half of the byte (4 bits, called a nibble) becomes one hex digit. Then hit the targets.

0 → hex 0

0 → hex 0

00000000 = 0 = 0x00

0=01=12=23=34=45=56=67=78=89=910=A11=B12=C13=D14=E15=F

🎯 Make the byte 0x2A

Name it

The real words

  • Hexadecimal (or just “hex”) is base 16. Each place is worth 16 times the place to its right: 0x2A = 2 × 16 + 10 = 42.
  • One hex digit = 4 bits (a nibble). One byte = 8 bits = 2 hex digits, from 00 to FF (0 to 255).
  • Prefixes tell you which system a number is in: 0x2A is hex, 0b101010 is binary, plain 42 is decimal.
Binary Hex Decimal
0000 0 0
1001 9 9
1010 A 10
1111 F 15
1111 1111 FF 255

Byte sizes:

Unit About Holds roughly
1 KB (kilobyte) 1,000 bytes a short email
1 MB (megabyte) 1,000,000 bytes a minute of MP3 music
1 GB (gigabyte) 1,000,000,000 bytes a short HD movie
1 TB (terabyte) 1,000,000,000,000 bytes 250,000 photos

Technically there are two systems. Storage makers use powers of 1,000. Computers often use powers of 2 (1,024 = 2¹⁰), properly written KiB, MiB, GiB. That’s why a “1 TB” drive shows up as about 931 GiB on your computer. Nothing’s missing; it’s two rulers measuring the same thing.

Build it

Convert by hand

What is 0x1F in decimal?

A color is #00FF00. What color is it?

Challenge

Sizes in your life

A song is about 4 MB. Roughly how many songs fit on a 64 GB phone (ignoring everything else)?

Remember it

How many bits does one hex digit stand for?

Got it?

Finish the lesson to color it in on your map and collect its concept cards.

Did this lesson click?