Lesson plan

Binary, hex and bits lesson plan

What a number really is, one bit a lamp: counting in binary, hex, AND OR XOR, shifts and masks, signed numbers and the lies floats tell. Ends with a binary clock you learn to read.

4 chapters, 7 lessons, about 5 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • Count in binary on ten lamps, then write it short in hex.
  • AND, OR and XOR, then shifts and masks.
  • Two's complement, then the float format and its lies.
  • A binary clock packed into ten lamps, and a quiz to read it.

Materials for the whole unit

  • Arduino Uno R3
  • Full-size breadboard
  • LED bar graph, 10 segments
  • Potentiometer
  • Resistor x 10

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 20 min

Base two

Count in binary on ten lamps, then write it short in hex.

LessonTimeWhat students do
Counting in binaryTen lamps, ten bits: a counter you can watch, what each lamp is worth, reading a binary number by hand, the biggest number ten bits hold, rolling over, and the knob as a 10-bit number.40 min
  1. Run it: a counter on ten lamps
  2. What each lamp is worth
  3. Read one by hand
  4. The biggest number ten lamps hold
  5. Roll it over
  6. The knob is a 10-bit number
Hex shorthandOne hex digit is exactly four bits: the sixteen digits, printing with %X, a hex parser written by hand that lights what you type, and making it take lower case too.40 min
  1. Run it: 0x2A
  2. Four bits a digit
  3. Type a hex number
  4. Light only the leftmost lamp
  5. Take lower case too
  6. Quick check: predict, then type

Materials

  • Arduino Uno R3
  • Full-size breadboard
  • LED bar graph, 10 segments
  • Potentiometer
  • Resistor x 10

Check for understanding

Each student finishes "Hex shorthand" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Quick check: predict, then type".

Chapter 2. About 1 h 20 min

Bit tricks

AND, OR and XOR, then shifts and masks.

LessonTimeWhat students do
AND OR XORLogic on every bit at once: AND keeps the bits a mask allows, OR forces bits on, XOR flips them, all tried on the knob, plus the XOR trick behind a cipher.40 min
  1. Run it: AND
  2. OR, XOR and NOT
  3. AND keeps what the mask allows
  4. OR forces bits on
  5. XOR flips them
  6. Quick check: XOR twice
Shifts and masksShifting left and right to multiply and divide by two, the four one-bit moves every firmware engineer knows (set, clear, toggle, test), pulling a field out of a number, and a scanner eye.40 min
  1. Run it: 1 << 3
  2. Shift right divides
  3. Set, clear, toggle, test
  4. Pull a field out
  5. A scanner eye
  6. Make the eye wider

Materials

  • Arduino Uno R3
  • Full-size breadboard
  • LED bar graph, 10 segments
  • Potentiometer
  • Resistor x 10

Check for understanding

Each student finishes "Shifts and masks" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make the eye wider".

Chapter 3. About 1 h 20 min

When bits mean numbers

Two's complement, then the float format and its lies.

LessonTimeWhat students do
Signed numbersHow eight bits hold -128 to 127: two's complement, flip and add one, the edges of an int8_t, one byte read two ways from the knob, and a submarine dive that does not fit.40 min
  1. Run it: -1 is all ones
  2. Flip and add one
  3. Off the edge
  4. One byte, two meanings
  5. A dive that does not fit
  6. Quick check: predict, then read
Floats and their liesA float is 32 bits of sign, exponent and fraction: ten dimes that miss a dollar by one bit, the bits of 1.0, a number too big to add one to, the knob as a float on the lamps, and comparing with a tolerance.40 min
  1. Run it: ten dimes
  2. Only four bytes
  3. Inside a float
  4. Too big to add one
  5. The knob as a float
  6. Compare with a tolerance

Materials

  • Arduino Uno R3
  • Full-size breadboard
  • LED bar graph, 10 segments
  • Potentiometer
  • Resistor x 10

Check for understanding

Each student finishes "Floats and their lies" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Compare with a tolerance".

Chapter 4. About 50 min

Project

A binary clock packed into ten lamps, and a quiz to read it.

LessonTimeWhat students do
Project: a binary clock readerEverything in one build: hours in four bits and minutes in six, packed into ten lamps with a shift and an OR, read back with a mask, a mask bug to find and fix, and a quiz that trains you to read the lamps. Then make it yours.50 min
  1. Run it: 10:28 in binary
  2. Packing two numbers into one
  3. The bug at 10:32
  4. Fix the mask
  5. Quiz: read the lamps
  6. Read one on your own
  7. Make it yours

Materials

  • Arduino Uno R3
  • Full-size breadboard
  • LED bar graph, 10 segments
  • Potentiometer
  • Resistor x 10

Check for understanding

Each student finishes "Project: a binary clock reader" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".

Your class

Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.