Lesson 5: Computing Fundamentals#
Ever wondered how computers actually work? How do they store photos, play music, and run programs? Letโs peek under the hood!
What Youโll Learn#
How computers store information (binary!)
What bits, bytes, and memory are
How text, images, and sound are stored
Computer hardware components
How the Internet works
Operating systems basics
๐ก Real-World Analogy#
Think of a computer like a kitchen:
CPU (processor) = The chef (does the work)
RAM (memory) = The countertop (temporary workspace)
Storage (hard drive) = The pantry (long-term storage)
Input = Ingredients you bring in
Output = The delicious meal you create!
1. The Binary System: How Computers Think#
Everything in a computer is stored as 0s and 1s!
Why Binary?#
Computers use electricity, which has two states:
0 = No electricity (OFF)
1 = Electricity flowing (ON)
This is called binary - a number system with only two digits (0 and 1).
How We Count vs How Computers Count#
Humans (Decimal - Base 10):
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
After 9, we go to 10 (one group of ten, zero ones)
Computers (Binary - Base 2):
Digits: 0, 1
After 1, we go to 10 (one group of two, zero ones)
Counting in Binary#
Decimal |
Binary |
Explanation |
|---|---|---|
0 |
0 |
Zero |
1 |
1 |
One |
2 |
10 |
One two, zero ones |
3 |
11 |
One two, one one |
4 |
100 |
One four, zero twos, zero ones |
5 |
101 |
One four, zero twos, one one |
6 |
110 |
One four, one two, zero ones |
7 |
111 |
One four, one two, one one |
8 |
1000 |
One eight, zero fours, zero twos, zero ones |
# Python can convert numbers to binary
number = 10
binary = bin(number) # bin() converts to binary string
print(f"The number {number} in binary is: {binary}")
print(f"Without '0b' prefix: {binary[2:]}")
# Let's see more examples
print("\nDecimal to Binary:")
for num in [1, 2, 5, 10, 16, 25, 100, 255]:
print(f"{num:3d} = {bin(num)[2:]}")
2. Understanding Binary Place Values#
Just like decimal has place values (ones, tens, hundreds), binary has place values too!
Decimal Place Values:#
1 2 3 4
โ โ โ โ
1000 100 10 1 (powers of 10)
Binary Place Values:#
1 0 1 0
โ โ โ โ
8 4 2 1 (powers of 2)
To convert binary to decimal:
Write the place values (8, 4, 2, 1)
If the binary digit is 1, add that place value
If the binary digit is 0, skip it
Example: 1010 in binary
Binary: 1 0 1 0
Value: 8 + 0 + 2 + 0 = 10
# Let's manually convert binary to decimal
def binary_to_decimal(binary_string):
"""
Convert binary string to decimal number.
Shows the step-by-step calculation.
"""
# Remove '0b' prefix if present
binary_string = binary_string.replace('0b', '')
print(f"Converting binary {binary_string} to decimal:")
print("\nPosition values (powers of 2):")
decimal = 0
length = len(binary_string)
# Show place values
place_values = [2 ** (length - 1 - i) for i in range(length)]
print("Position:", ' '.join(str(pv).rjust(4) for pv in place_values))
print("Binary: ", ' '.join(digit.rjust(4) for digit in binary_string))
# Calculate
calculation = []
for i, digit in enumerate(binary_string):
position = length - 1 - i
value = 2 ** position
if digit == '1':
decimal += value
calculation.append(str(value))
else:
calculation.append('0')
print("Values: ", ' + '.join(val.rjust(4) for val in calculation))
print(f"\nResult: {decimal}")
return decimal
# Test it
binary_to_decimal("1010")
print("\n" + "="*40 + "\n")
binary_to_decimal("1111")
# Convert binary to decimal (Python's way)
binary_string = "0b1010" # '0b' prefix means binary
decimal = int(binary_string, 2) # Convert from base 2
print(f"Binary {binary_string} = Decimal {decimal}")
# Try more examples
binary_numbers = ["1", "10", "11", "100", "101", "110", "111", "1000"]
print("\nBinary to Decimal conversions:")
for binary in binary_numbers:
decimal = int(binary, 2)
print(f"{binary:>4s} = {decimal}")
3. Bits and Bytes: Storage Units#
The Building Blocks#
Bit (Binary Digit):
The smallest unit of data
Can be either 0 or 1
Like a single light switch (on or off)
Byte:
8 bits grouped together
Can store values from 0 to 255
Can represent one character (like โAโ or โ5โ)
Storage Size Hierarchy#
Unit |
Size |
Example |
|---|---|---|
1 Bit |
0 or 1 |
One light switch |
1 Byte |
8 bits |
One character (โAโ) |
1 Kilobyte (KB) |
1,024 bytes |
One page of text |
1 Megabyte (MB) |
1,024 KB |
One high-quality photo |
1 Gigabyte (GB) |
1,024 MB |
About 1 hour of HD video |
1 Terabyte (TB) |
1,024 GB |
250,000 songs |
Why 1024 instead of 1000?#
Because computers use binary! 1024 = 2^10, which is more natural for computers than 1000.
# Understanding byte capacity
print("What can 1 byte (8 bits) store?")
print(f"Minimum value: {0}")
print(f"Maximum value: {2**8 - 1} (255)")
print(f"Total possible values: {2**8} (0-255)")
print("\nIn binary:")
print(f"Smallest: {bin(0)}")
print(f"Largest: {bin(255)} (11111111)")
# Convert bytes to human-readable format
def bytes_to_readable(bytes_count):
"""
Convert bytes to human-readable format.
"""
if bytes_count < 1024:
return f"{bytes_count} bytes"
elif bytes_count < 1024 * 1024:
return f"{bytes_count / 1024:.2f} KB"
elif bytes_count < 1024 * 1024 * 1024:
return f"{bytes_count / (1024 * 1024):.2f} MB"
elif bytes_count < 1024 * 1024 * 1024 * 1024:
return f"{bytes_count / (1024 * 1024 * 1024):.2f} GB"
else:
return f"{bytes_count / (1024 * 1024 * 1024 * 1024):.2f} TB"
# Test with different file sizes
print("File Size Examples:")
print(f"Text file: {bytes_to_readable(500)}")
print(f"Small image: {bytes_to_readable(50000)}")
print(f"Song (MP3): {bytes_to_readable(5000000)}")
print(f"HD Movie: {bytes_to_readable(5000000000)}")
print(f"Video game: {bytes_to_readable(50000000000)}")
4. Text Encoding: How Computers Store Text#
Computers donโt actually store letters - they store numbers! Text encoding is the system that maps letters to numbers.
ASCII (American Standard Code for Information Interchange)#
Created in 1963
Uses 7 bits (128 characters)
Includes: A-Z, a-z, 0-9, punctuation, control characters
Example ASCII Codes:
โAโ = 65
โBโ = 66
โaโ = 97
โ0โ = 48
โ โ (space) = 32
Unicode / UTF-8#
Modern standard for text
Can represent ALL languages and emojis!
UTF-8 can use 1-4 bytes per character
Backward compatible with ASCII
# Working with ASCII codes
letter = 'A'
code = ord(letter) # ord() gets the ASCII/Unicode code
print(f"Letter '{letter}' has code: {code}")
print(f"In binary: {bin(code)}")
# Convert code back to letter
code = 65
letter = chr(code) # chr() converts code to character
print(f"\nCode {code} represents: '{letter}'")
# Encode a message
message = "HELLO"
print(f"Encoding message: '{message}'\n")
print("Letter | ASCII Code | Binary")
print("-------|------------|------------------")
for char in message:
code = ord(char)
binary = bin(code)[2:].zfill(8) # 8-bit binary
print(f" {char} | {code:3d} | {binary}")
# Calculate storage needed
bytes_needed = len(message)
bits_needed = bytes_needed * 8
print(f"\nStorage needed: {bytes_needed} bytes ({bits_needed} bits)")
# Uppercase vs lowercase
print("Notice the pattern between uppercase and lowercase:\n")
letters = ['A', 'a', 'B', 'b', 'Z', 'z']
for letter in letters:
print(f"'{letter}' = {ord(letter):3d} = {bin(ord(letter))}")
print("\nDifference: lowercase = uppercase + 32")
print("In binary, that's flipping one bit!")
# Modern Unicode: Emojis!
emojis = ['๐', 'โค๏ธ', '๐', '๐ป', '๐']
print("Unicode for Emojis:\n")
for emoji in emojis:
code = ord(emoji)
print(f"{emoji} = {code} (needs more than 1 byte!)")
5. Computer Components: The Hardware#
The Main Parts of a Computer#
1. CPU (Central Processing Unit) ๐ง
The โbrainโ of the computer
Performs calculations and executes instructions
Measured in GHz (billions of operations per second)
Example: Intel Core i7, Apple M1
2. RAM (Random Access Memory) ๐
Short-term memory (temporary workspace)
Fast but volatile (loses data when power off)
Holds currently running programs and data
Typical size: 8GB - 32GB
3. Storage (Hard Drive / SSD) ๐พ
Long-term memory (permanent storage)
Persistent (keeps data when power off)
Stores files, programs, operating system
HDD (slower, cheaper) vs SSD (faster, expensive)
4. GPU (Graphics Processing Unit) ๐ฎ
Specialized processor for graphics and parallel tasks
Essential for gaming, video editing, AI/ML
Example: NVIDIA GeForce, AMD Radeon
5. Motherboard ๐
Connects all components together
The โnervous systemโ of the computer
6. Input Devices โจ๏ธ๐ฑ๏ธ
Keyboard, mouse, touchscreen, microphone
How you communicate with the computer
7. Output Devices ๐ฅ๏ธ๐
Monitor, speakers, printer
How the computer communicates with you
How They Work Together#
Input โ RAM โ CPU โ RAM โ Output
โ โ โ
โโโ Storage โโโ
Example: Opening a photo
You click the photo file (Input)
OS loads photo from Storage to RAM
CPU processes image data
GPU renders the image
Image displays on Monitor (Output)
6. How Data is Represented#
Everything is stored as binary, but how?
Images ๐ผ๏ธ#
Pixels: Tiny dots of color
Each pixel stores RGB values (Red, Green, Blue)
Each color component: 0-255 (1 byte)
Total per pixel: 3 bytes
Example: 1920x1080 image = 2,073,600 pixels ร 3 bytes = ~6MB
Audio ๐ต#
Sampling: Record sound at regular intervals
CD quality: 44,100 samples per second
Each sample: 2 bytes
Stereo (2 channels) ร 44,100 ร 2 bytes = ~172KB per second
3-minute song = ~30MB uncompressed
Video ๐ฌ#
Sequence of images (frames) + audio
30 frames per second (fps) is standard
HD video (1920x1080, 30fps) = ~60MB per second uncompressed!
Compression (H.264, H.265) reduces to ~5MB per second
Compression#
Reduces file size by removing redundant data
Lossy: Some quality lost (JPEG, MP3, MP4)
Lossless: Perfect quality (PNG, FLAC, ZIP)
# Calculate image storage size
def calculate_image_size(width, height, bits_per_pixel=24):
"""
Calculate uncompressed image size.
24 bits = 3 bytes (RGB)
"""
total_pixels = width * height
bytes_per_pixel = bits_per_pixel // 8
total_bytes = total_pixels * bytes_per_pixel
print(f"Image: {width}x{height}")
print(f"Total pixels: {total_pixels:,}")
print(f"Bytes per pixel: {bytes_per_pixel}")
print(f"Uncompressed size: {bytes_to_readable(total_bytes)}")
print()
# Common image resolutions
calculate_image_size(640, 480) # VGA
calculate_image_size(1920, 1080) # Full HD
calculate_image_size(3840, 2160) # 4K
7. Operating Systems#
An Operating System (OS) manages all computer resources and provides services to programs.
What Does an OS Do?#
Manages Hardware
Controls CPU, memory, storage, devices
Allocates resources to programs
Provides User Interface
GUI (Graphical User Interface) - Windows, icons, menus
CLI (Command Line Interface) - Text commands
Runs Programs
Loads programs into memory
Manages multiple programs at once (multitasking)
Manages Files
Organizes files in folders
Handles reading/writing files
Security
User accounts and permissions
Protects against malware
Popular Operating Systems#
Desktop:
Windows (Microsoft)
macOS (Apple)
Linux (Open source - Ubuntu, Fedora, etc.)
Mobile:
Android (Google)
iOS (Apple)
Servers:
Linux (most web servers)
Windows Server
8. Networks and the Internet#
How Computers Communicate#
Network: Connected computers that can share data
Internet: The worldwide network of networks
Key Concepts#
1. IP Address
Unique identifier for each device
Like a street address for your computer
Example: 192.168.1.1 (IPv4)
2. Packets
Data broken into small chunks
Each packet travels independently
Reassembled at destination
3. Protocols
Rules for communication
HTTP/HTTPS: Web pages
TCP/IP: How packets are sent
DNS: Translates domain names to IP addresses
4. Bandwidth
How much data can transfer per second
Measured in Mbps (megabits per second)
Example: 100 Mbps = ~12 MB per second
What Happens When You Visit a Website?#
You type โwww.google.comโ in browser
DNS converts domain to IP address
Browser sends HTTP request to Googleโs server
Server sends back HTML, CSS, JavaScript
Browser renders the page
All in milliseconds!
9. How Programs Work#
The Execution Cycle#
Fetch: CPU gets instruction from memory
Decode: CPU figures out what the instruction means
Execute: CPU performs the operation
Store: CPU saves the result
This happens billions of times per second!
Programming Languages#
Low Level (closer to computer):
Machine Code: Binary (0s and 1s)
Assembly: Symbolic machine code (MOV, ADD, SUB)
High Level (closer to human):
Python, JavaScript, Java, C++
Easier to read and write
Needs to be compiled or interpreted to machine code
Compilation vs Interpretation:
Compiled: Translated all at once (C, C++, Go)
Interpreted: Translated line-by-line (Python, JavaScript)
๐ Exercises#
Exercise 1: Binary Converter#
Create a program that:
Takes a decimal number
Converts it to binary
Shows the place values
Verifies by converting back
Test with: 10, 25, 100, 255
# Your code here
Exercise 2: Word Analyzer#
Create a function that takes a word and:
Converts each letter to ASCII code
Shows the binary representation
Calculates total storage needed (bytes and bits)
Test with: โCODEโ, โPYTHONโ, โHELLO WORLDโ
# Your code here
Exercise 3: Storage Calculator#
Create a program that calculates storage for different media:
Text file: 1 byte per character
Image: width ร height ร 3 bytes
Audio: seconds ร 44,100 ร 2 bytes
Calculate storage for:
A 5-page essay (2000 characters)
A 1920ร1080 photo
A 3-minute song
# Your code here
Exercise 4: Secret Message Encoder#
Create a simple encoder/decoder:
Convert text to ASCII codes
Add 3 to each code (Caesar cipher!)
Convert back to text
Create decoder that subtracts 3
Test by encoding and decoding: โHELLOโ
# Your code here
Exercise 5: Download Time Calculator#
Create a function that calculates download time:
Input: file size (MB), internet speed (Mbps)
Remember: 1 Byte = 8 bits
Output: time in seconds and minutes
Calculate download time for:
100 MB file at 10 Mbps
5 GB movie at 100 Mbps
50 GB game at 50 Mbps
# Your code here
Exercise 6: Computer Spec Analyzer#
Create a program that rates computer specs:
Rate CPU speed (GHz): >3.0 = Fast, 2.0-3.0 = Medium, <2.0 = Slow
Rate RAM (GB): >16 = Great, 8-16 = Good, <8 = Low
Rate Storage (GB): >500 = Spacious, 250-500 = Adequate, <250 = Limited
Test with different configurations and give an overall rating.
# Your code here
โ Self-Check Quiz#
Before moving on, make sure you can answer these:
What is binary and why do computers use it?
How many values can 1 byte (8 bits) store?
Whatโs the difference between a bit and a byte?
How many bytes in a kilobyte? Why 1024 and not 1000?
What is ASCII?
What does the CPU do?
Whatโs the difference between RAM and storage?
What is an operating system?
What is an IP address?
How is text stored in a computer?
๐ฏ Key Takeaways#
Binary is how computers store everything (0s and 1s)
1 Bit = one 0 or 1
1 Byte = 8 bits (can store 0-255)
Storage hierarchy: Byte โ KB โ MB โ GB โ TB
ASCII/Unicode maps characters to numbers
CPU = brain (processes), RAM = short-term memory, Storage = long-term memory
Operating System manages hardware and runs programs
Internet = worldwide network of computers
Everything (text, images, audio, video) is ultimately stored as binary
๐ Next Steps#
Congratulations! You now understand how computers work at a fundamental level!
Youโve completed the Easy level! ๐
You now have a solid foundation in:
โ Python programming basics
โ Variables and data types
โ Operations and conditionals
โ AI and machine learning concepts
โ How computers work
Ready for more?
Medium Level: Functions, loops, data structures, OOP
Developer Tools:
tools/01_shell_basics.ipynb- Essential professional skillsHard Level: Advanced algorithms, deep learning, computer systems
๐ก Pro Tips#
Everything is binary: Understanding this helps debug and optimize code
Memory matters: Efficient programs use less RAM and storage
Compression is magic: Reduces file sizes dramatically
Think in powers of 2: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024โฆ
Network speed: Bits vs Bytes - divide Mbps by 8 for MB/s
Modern computers are fast: Billions of operations per second!
But theyโre still limited: Good code respects resource constraints
๐ Fun Facts#
Apollo 11 (1969 moon landing) had only 4KB of RAM!
Your phone has over 1,000,000 times more RAM
The first 1GB hard drive (1980) weighed 550 pounds and cost $40,000
Today you can buy 1TB (1,000 GB) for $50
ENIAC (1945), the first computer, weighed 30 tons
Modern smartphones are millions of times more powerful
Every Google search involves thousands of computers
Netflix streams over 1 billion hours per week
The Internet transmits about 2.5 quintillion bytes per day!
Youโve learned the fundamentals - now go build amazing things! ๐