Skip to main content

Lesson 1: Understanding Binary - From 0 and 1 to the Computer World

๐Ÿ“Œ Learning Objectivesโ€‹

  1. Understand what binary is
  2. Master conversion between decimal and binary
  3. Understand the role of binary in microcontrollers
  4. Experience practical applications of binary through experiments

๐ŸŽฏ What is Binary?โ€‹

Review of Decimalโ€‹

We use decimal in daily life, which has 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

Rule: Carry over when reaching 10

  15
+ 8
----
23

Introduction to Binaryโ€‹

Computers use binary, which has only 2 digits: 0 and 1.

Rule: Carry over when reaching 2

  101
+ 1
----
110

๐Ÿ”„ Decimal โ†” Binary Conversionโ€‹

Decimal โ†’ Binary: Divide by 2, Collect Remaindersโ€‹

Example: Convert decimal 13 to binary

13 รท 2 = 6  remainder 1  โ† least significant bit
6 รท 2 = 3 remainder 0
3 รท 2 = 1 remainder 1
1 รท 2 = 0 remainder 1 โ† most significant bit

Result: 1101

Binary โ†’ Decimal: Weighted Sumโ€‹

Example: Convert binary 1011 to decimal

1    0    1    1
โ†“ โ†“ โ†“ โ†“
2ยณ 2ยฒ 2ยน 2โฐ
8 4 2 1

8 + 0 + 2 + 1 = 11

๐Ÿ’ก The Meaning of Binary in Microcontrollersโ€‹

1. Representing Switch Statesโ€‹

  • 0 = OFF
  • 1 = ON

2. Representing Logicโ€‹

  • 0 = False
  • 1 = True

3. Register Storageโ€‹

Microcontroller registers store data in binary!


๐Ÿ”ฌ Classroom Demo: Binary LED Arrayโ€‹

Experiment Goalโ€‹

Use 4 LEDs to represent a 4-bit binary number, counting from 0 to 15.

Hardware Connectionsโ€‹

LEDConnectionBinary Bit
LED1Output 02โฐ (1)
LED2Output 12ยน (2)
LED3Output 22ยฒ (4)
LED4Output 32ยณ (8)

Example Codeโ€‹

; Count from 0 to 15, display binary with LEDs
000 01 0000 0000 ; 0 (0000)
001 02 03E8 0000 ; delay
002 01 0001 0000 ; 1 (0001)
003 02 03E8 0000 ; delay
004 01 0002 0000 ; 2 (0010)
005 02 03E8 0000 ; delay
006 01 0003 0000 ; 3 (0011)
007 02 03E8 0000 ; delay
008 0E 0000 0000 ; loop

Teaching Suggestionsโ€‹

Ask students to guess what the next number will be, or let them design their own counting program.


๐Ÿ“Š Common Decimal-Binary Conversion Tableโ€‹

DecimalBinaryHex
000000x00
100010x01
200100x02
300110x03
401000x04
501010x05
810000x08
1010100x0A
1511110x0F
160001 00000x10
2551111 11110xFF

โœ… Quick Quizโ€‹

  1. What is decimal 7 in binary?
  2. What is binary 1101 in decimal?
  3. What's the maximum value of an 8-bit binary number? (Answer: 255)

๐ŸŽ‰ Summaryโ€‹

What we learned today:

  • โœ… Binary only has 0 and 1
  • โœ… Can convert using divide-by-2 and weighted sum methods
  • โœ… Binary represents switch states and logic values
  • โœ… LED arrays can visually demonstrate binary

Next lesson, we'll learn about registers and see how binary is stored in microcontrollers!