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.
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?"
22 = 4 (too small).
23 = 8 โฅ 5 โ.
Use 3 bits.
"We have 1,000,000 user IDs. Minimum bits per ID?"
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
28
256
2
Text: Each character mapped to a number (ASCII: 7 bits, Unicode: up to 32 bits)
Colors: RGB values (each 0-255 = 8 bits, total 24 bits per pixel)
Sound: Sampled as numbers at regular intervals (sampling rate x bit depth)
1
Bit
0
1
0
1
1
0
0
1
Sum the places where the bit is 1: 64 + 16 + 8 + 1 = 89.
Going The Other Way
To convert decimal โ binary, repeatedly subtract the largest power of 2 that fits.
Convert 45:
32 fits โ bit on; remainder 13.
16 doesn't fit; bit off.
8 fits โ bit on; remainder 5.
4 fits โ bit on; remainder 1.
2 doesn't fit; bit off.
1 fits โ bit on; remainder 0.
Result: 00101101 (8 bits).
Why "n bits = 2n values"
Each new bit doubles the patterns:
Bits
Patterns
1
2
2
4
4
16
8
256
16
65,536
32
~4.3 billion
Memorize 28 = 256 and 216 = 65,536 โ both appear constantly on the AP exam.
Applied Recall โ๏ธ
A single binary digit (0 or 1) is called a _______.
The number of distinct values that can be represented with n bits is 2 to the _______ power.
The decimal number 5 in 4-bit binary is _______.
Targeted Practice ๐
AP Exam Strategy: Binary Conversions
Write the place-value row first; then plug in the bits.
Pixels: ยผ of a row of an image (each byte a grayscale level)
The interpretation lives in the program reading the file, not in the file itself. File extensions (".txt", ".png") and headers (magic bytes at the start of the file) tell programs how to interpret bytes.
Lossless Encoding Connections
Compression (next part) takes a bit pattern and produces a shorter one that decodes back to the same original. Encryption takes a bit pattern and produces a same-length one that only decodes with a key. Both rely on the universality of bits.
Applied Recall โ๏ธ
On a network, all data โ text, image, video โ is transmitted as _______.
The same byte sequence can have different meanings depending on how the program _______ it.
A short magic-bytes signature at the start of a file tells programs the file _______.
Targeted Practice ๐
AP Exam Strategy: Cross-Topic Binary Questions
"How is X transmitted on the Internet?" โ bits, regardless of X.
"What does a byte sequence MEAN?" โ the encoding scheme decides.
Encryption and compression are both bit-pattern transformations.
File extension โ guarantee: malicious bytes can be mislabeled. (Hence: never rely on extension for security.)
AP-Style Application ๐ฏ
Lossy
Decoded data is approximately the original.
JPEG, MP3, MP4
Photos, music, video where small artifacts are tolerable.
Why Both Exist
Lossless can't compress beyond a hard math limit (entropy). For a truly random file, no lossless compression helps.
Lossy can compress much further by exploiting human perception (we don't notice many high frequencies in audio or subtle color shifts in images).
A 24-bit RGB photo: ~6 MB raw, ~600 KB as JPEG (10ร smaller, almost identical to the eye).
Storage Scaling Has Changed Behavior
Cheap storage made it normal to keep everything (logs, backups).
AI training relies on datasets that would have been physically impossible to store in 2000.
Cheap copies = quick spread = new questions about consent, copyright, and privacy.
Applied Recall โ๏ธ
Compression that decodes back to a bit-for-bit identical original is called _______.
Compression that throws away some data to shrink the file is called _______.
JPEG and MP3 are examples of _______ compression.
Targeted Practice ๐
AP Exam Strategy: Compression Choices
"Original must be perfectly recoverable" โ lossless.
"File needs to be much smaller and small artifacts are okay" โ lossy.