Binary & Data Representation - Complete Interactive Lesson
Part 1: Core Concepts
๐ป Binary & Data Representation
Part 1 of 7 โ Binary Numbers, Conversions, and Digital Information
Why Binary?
Computers use binary (base-2) because electronic circuits have two states: ON (1) and OFF (0). ALL data โ numbers, text, images, sound โ is ultimately stored as sequences of 0s and 1s.
| Base | Name | Digits Used | Example |
|---|---|---|---|
| Base-2 | Binary | 0, 1 | 1010 |
| Base-10 | Decimal | 0-9 | 10 |
| Base-16 | Hexadecimal | 0-9, A-F | A |
Binary to Decimal Conversion
Each binary digit (bit) represents a power of 2:
| Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Example: 1101 in binary = ?
- 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1 = 8 + 4 + 0 + 1 = 13
Example: 10110 in binary = ?
- 1 x 16 + 0 x 8 + 1 x 4 + 1 x 2 + 0 x 1 = 16 + 4 + 2 = 22
๐ With n bits, you can represent 2^n different values (0 to 2^n - 1). 8 bits = 1 byte = 256 values.
Concept Check ๐ฏ
Decimal to Binary Conversion
Repeatedly divide by 2 and track remainders (read bottom to top):
Convert 25 to binary:
- 25 / 2 = 12 remainder 1
- 12 / 2 = 6 remainder 0
- 6 / 2 = 3 remainder 0
- 3 / 2 = 1 remainder 1
- 1 / 2 = 0 remainder 1
- Read upward: 11001
Overflow
When a value exceeds the number of bits available:
- 4 bits can store 0-15
- If you try to store 16 in 4 bits, it overflows back to 0
- This is like an odometer rolling over from 999 to 000
Data Units
| Unit | Size |
|---|---|
| Bit | Single 0 or 1 |
| Byte | 8 bits |
| Kilobyte (KB) | ~1,000 bytes |
| Megabyte (MB) | ~1,000 KB |
| Gigabyte (GB) | ~1,000 MB |
| Terabyte (TB) | ~1,000 GB |
Representing Other Data Types
Applied Recall โ๏ธ
-
A single binary digit (0 or 1) is called a _______.
-
8 bits make up one _______.
-
With n bits, you can represent _______ to the power of n different values.
Binary Practice ๐
AP Exam Strategy: Binary & Data
- Memorize powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024
- Know both conversions: binary-to-decimal and decimal-to-binary
- With n bits: 2^n values, range 0 to 2^n - 1
- Overflow = value exceeds bit capacity. AP loves testing this concept
- Know how text (ASCII/Unicode), images (RGB pixels), and sound (samples) are stored in binary
- One additional bit DOUBLES the representable values โ this is the key relationship
AP-Style Application ๐ฏ
Part 2: Key Processes
๐ข Binary & Data Representation
Part 2 of 7 โ Key Processes
How Computers Encode Everything in Binary
A computer represents every kind of data โ numbers, text, images, sound โ using only two digits: 0 and 1. The trick is agreement: a sender and receiver agree on a code, then the same bit pattern can mean a number, a letter, or a pixel color.
| Data type | Encoding scheme |
|---|---|
| Whole number | Place values 1, 2, 4, 8, 16, โฆ (binary) |
| Text | A code mapping bit pattern โ character (e.g., ASCII) |
| Color (pixel) | Three numbers: R, G, B โ each 8 bits |
| Sound | Repeated samples of air-pressure amplitude |
Concept Check ๐ฏ
Reading Binary Like a Pro
To convert binary to decimal, line up the bits with their place values from the right and add the place values where the bit is 1.
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 |
|---|
Part 3: Patterns & Examples
๐ข Binary & Data Representation
Part 3 of 7 โ Patterns & Examples
Patterns of Encoding
Computers use conventions to encode data types. Understanding the convention is half the work.
| Convention | Pattern |
|---|---|
| Unsigned integer | Plain place-value binary. |
| Signed integer | Reserves one bit for sign (e.g., two's complement). |
| Text (ASCII) | 7-bit code; "A" = 65, "a" = 97. |
| Text (Unicode) | Variable-length; supports every script. |
| RGB color | Three 8-bit channels: 0โ255 red, green, blue. |
| Sample (audio) | Integer amplitude, repeated at sample rate. |
Concept Check ๐ฏ
Worked Example: Decoding Text
Bytes: 72, 73, 33
- 72 = "H"
- 73 = "I"
- 33 = "!"
Output: HI! Since text is just numbers under an agreed mapping, any file is bytes โ the difference is only how the program interprets them.
Worked Example: Building a Color
Part 4: Connections & Interactions
๐ข Binary & Data Representation
Part 4 of 7 โ Connections & Interactions
Why Binary Connects To Everything Else
The "everything is bits" idea makes the rest of the course possible.
| Topic | Connection |
|---|---|
| Internet (BI 4) | All packets are bits, regardless of media (fiber, copper, radio). |
| Algorithms (BI 3) | Algorithms manipulate bit patterns โ search, sort, compress. |
| Compression (BI 2) | Encode the same data in fewer bits. |
| Security (BI 4) | Encryption transforms bits into other bits unreadable without a key. |
| Impact (BI 5) | A digital file is trivial to copy and share โ that changes society. |
Concept Check ๐ฏ
Bits Are Format-Agnostic
A network router doesn't know whether the bits it forwards are an image, a song, or a chess move. It only knows source/destination headers and the payload bits. This is why a single Internet works for so many uses โ the binary layer is universal.
Same Bytes, Different Meaning
A 4-byte sequence 01000001 01000010 01000011 01000100 could mean:
- Text (ASCII): "ABCD"
- Four small unsigned integers: 65, 66, 67, 68
Part 5: Change Over Time
๐ข Binary & Data Representation
Part 5 of 7 โ Change Over Time
How Storage And Encoding Have Scaled
Storage costs have collapsed and bit budgets have grown. The same data that filled a hard drive in 2000 fits in a phone's photo cache today.
| Era | Typical "lots of data" |
|---|---|
| 1980s | Megabytes. ASCII text dominated. |
| 1990s | Hundreds of MB. JPEG and MP3 made images/audio mainstream. |
| 2000s | Gigabytes. DVDs, MP3 collections, digital cameras. |
| 2010s | Terabytes. Streaming video became default. |
| 2020s | Petabytes (in datacenters). 4K, 8K video, AI training datasets. |
Concept Check ๐ฏ
Lossless vs. Lossy
| Type | Guarantee | Examples | When to use |
|---|---|---|---|
| Lossless | Decoded data = original, bit for bit. | ZIP, PNG, FLAC | Documents, source code, medical imaging. |
Part 6: Problem-Solving Workshop
๐ข Binary & Data Representation
Part 6 of 7 โ Problem-Solving Workshop
Binary & Data Workshop
Practice the calculations and design choices the AP exam asks under a time crunch.
Concept Check ๐ฏ
Worked: Bit-Width Sizing
Question: "We have 5 different statuses to encode in each record. Minimum bits per record?"
- 2ยฒ = 4 (too small).
- 2ยณ = 8 โฅ 5 โ.
- Use 3 bits.
Question: "We have 1,000,000 user IDs. Minimum bits per ID?"
- 2ยนโน = 524,288 (too small).
- 2ยฒโฐ = 1,048,576 โฅ 1M โ.
- Use 20 bits.
Worked: Storage Estimation
Question: "Estimate the storage for 10,000 1024ร1024 RGB photos, uncompressed."
- One photo: 1024 ร 1024 ร 3 โ 3 MB.
- 10,000 photos: ~30 GB.
With JPEG (~10ร): ~3 GB.
Worked: Conversions Both Ways
| Decimal | Binary (8-bit) |
|---|---|
| 5 | 00000101 |
| 17 | 00010001 |
| 64 | 01000000 |
| 100 | 01100100 |
Part 7: AP Review
๐ข Binary & Data Representation
Part 7 of 7 โ AP Review
AP Exam Recap โ Binary & Data
Final cheat sheet of the binary and data-representation facts most tested on the AP exam.
Concept Check ๐ฏ
Quick-Reference Table
| Memorize | Value |
|---|---|
| 1 byte | 8 bits |
| 2โธ | 256 |
| 2ยนโฐ | 1,024 (โ 1 KB) |
| 2ยนโถ | 65,536 |
| 2ยฒโฐ | โ 1 million (โ 1 MB) |
| 2ยณยฒ | โ 4.3 billion (โ 4 GB) |
Common Misconceptions to Avoid
- "Binary uses 0 and 1 because computers think in numbers." (No โ because hardware reliably represents two voltage levels.)
- "Lossy compression destroys the file." (No โ it produces a smaller approximation; original can be saved separately.)
- "More bits is always better." (No โ wasted bits = wasted storage / bandwidth. Use the minimum sufficient.)
- "Encryption shrinks data." (No โ it transforms data; size stays roughly the same.)
Common Calculations
- Min bits for N values: โlogโ Nโ.
- Image bytes: W ร H ร bytesPerPixel.
- Audio bytes/sec: sampleRate ร bytesPerSample ร channels.
- Total storage of M items ร k bytes each: Mยทk.
โ๏ธ