Lite / Building Machines That Respond / Week 17
Binary and hexadecimal
A sensor datasheet says its ID register reads 0x6B. What number is that, and why would anyone write it that way?
Why should I care?
Registers, memory addresses, colours and network packets are all written in binary or hex. Fluent conversion is the everyday language of anyone who works close to the hardware.
- Convert between decimal, binary and hexadecimal using place values.
- State the range of values n bits can hold (0 to 2ⁿ − 1).
- Explain why engineers write long binary numbers in hex.
Predict
What is the largest number you can store in 8 bits?
- 8
- 128
- 255
- 256
Guess first, then reveal
Eight 1s: 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255. There are 256 different patterns, but one of them is 0, so the largest is 255 = 2⁸ − 1.
Discover
Do Level 1 of the virtual computer: show 13, 6 and 9 on the 4-bit register, turn 1010 and 0111 back into numbers, find the largest 4-bit number, and predict what 1111 + 1 shows.
What the interactive shows (text version)
In the virtual computer's 4-bit register, lamps show the bits: 13 is 1101, 6 is 0110 and 9 is 1001; 1010 is 10 and 0111 is 7. The largest 4-bit number is 15 (1111), and adding 1 to 1111 gives 0000 because the carry falls off the top.
Watch (optional)
Watch for: Watch for place values doubling from right to left, and how the same idea stretches to letters and colours.
Shows how ones and zeros can stand for numbers and text, so binary stops feeling like magic.
“Representing Numbers and Letters with Binary: Crash Course Computer Science #4” by CrashCourse (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
Place values that double
In binary each place is worth twice the one to its right: 1, 2, 4, 8, 16, 32, 64, 128. 1011 = 8 + 0 + 2 + 1 = 11. To go the other way, take away the biggest power of 2 that fits and repeat: 13 = 8 + 4 + 1 = 1101.
How much fits
n bits make 2ⁿ patterns, holding 0 to 2ⁿ − 1. 4 bits: 0 to 15. 8 bits (a byte): 0 to 255. 16 bits: 0 to 65,535. Each extra bit doubles the range.
Hex: four bits per digit
Hexadecimal has 16 digits: 0–9 then A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Each hex digit is exactly four bits, so a byte is two hex digits: 0x6B = 0110 1011 = 6 × 16 + 11 = 107. 0xFF = 255. The '0x' just marks a number as hex.
Explain it another way
Intuitive
Binary is counting with only two fingers per place. Hex is a shorthand that packs four of those places into one symbol, the way '1 dozen' packs twelve eggs.
Technical
A positional system in base b represents Σ dₖ·bᵏ. Since 16 = 2⁴, each hex digit maps to a fixed 4-bit group (a nibble), making conversion a lookup rather than arithmetic.
Mathematical
0x2A = 2 × 16 + 10 = 42 = 0010 1010. 200 = 128 + 64 + 8 = 1100 1000 = 0xC8.
Applied
Colours on web pages are three bytes in hex: #FF8000 is full red, half green, no blue. Debuggers show memory in hex because each pair of digits is one byte.
Worked example 1
Convert 0xC8 to binary and decimal.
C = 12 = 1100 and 8 = 1000, so 1100 1000. Decimal: 12 × 16 + 8 = 200.
Common mix-ups
8 bits can hold numbers up to 256.
✓ 8 bits make 256 patterns, but they start at 0, so the largest is 255.Hex is a different kind of number.
✓ It is the same number written in base 16; only the notation changes.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Complete BUILD 008 Level 1. Then write your age, the day of the month and 200 in binary and in hex, and check each with the 4-bit or 8-bit register in the adder stepper.
Reflect
Why do you think computers use base 2 while people use base 10?
Write your answer on paper or in your own notes. Lite never stores what you write.