How many bits do you need for 100 different things?
72⁶ = 64 is too few, 2⁷ = 128 is enough.
Encode aaaaaaabbbcccccc with run-length encoding. What is the ratio?
*a7bbb*c6, ratio 9/16 = 0.5625bbb stays as is because 3 repeats aren't worth encoding.
Is 178 a valid base-8 number?
No.Base 8 only uses digits 0 to 7.
Temporal or spatial: comparing one frame to the next?
Temporal.
Chapter 3Computer Components
Gates are built from transistors
A logic gate is made of a few transistors.
A transistor is a tiny switch with no moving parts.
Depending on the input voltage, it either lets electricity through (like a wire) or blocks it (like a resistor).
It is made of a semiconductor, which is neither a good conductor nor a good insulator.
How it stacks up:
A few transistors make one logic gate.
Millions of gates make one integrated circuit (chip), with billions of transistors.
Tens or hundreds of chips sit on the motherboard.
From the textbook: a NOT gate uses 1 transistor, NAND and NOR use 2, AND and OR use 3.
A gate does one basic job on electrical signals. A circuit is several gates joined together. The most important chip is the CPU.
The gates
NOT flips the input. 1 becomes 0, 0 becomes 1.
AND gives 1 only if both inputs are 1.
OR gives 1 if at least one input is 1.
XOR gives 1 if the inputs are different.
NAND is the opposite of AND. NOR is the opposite of OR.
A
B
AND
OR
XOR
NAND
NOR
0
0
0
0
0
1
1
0
1
0
1
1
1
0
1
0
0
1
1
1
0
1
1
1
1
0
0
0
OR and XOR only differ on the last row, when both inputs are 1. You can describe a gate three ways: a Boolean expression, a logic diagram, or a truth table.
Parts of the computer (von Neumann)
Part
What it does
Memory
Holds both the program and the data
ALU
Does math (+, −) and logic (AND, OR, NOT)
Control unit
Runs the show
Input / output
Keyboard and mouse in, screen and printer out
Bus
Carries data between the parts
ALU + control unit = CPU.
PC (program counter) holds the address of the next instruction.
IR (instruction register) holds the instruction running now.
Registers are tiny, super fast storage inside the CPU.
A 3.2 GHz CPU ticks 3.2 billion times a second.
Fetch-execute cycle
Fetch the next instruction.
Decode it.
Get data if needed.
Execute it.
Then it starts again, which is why it's called a cycle.
Memory
RAM can be read and changed. It is volatile, so it is wiped when the power goes off.
ROM can only be read. It keeps its data.
Secondary storage keeps data for good: hard disk, SSD, USB drive, CD.
Fastest to slowest: registers → cache → RAM → secondary storage → tape and discs. The faster it is, the smaller and more expensive it is.
Embedded systems
A small computer built into something bigger to do one job. Examples: computers in cars, phones and medical equipment.
Quick check
Use the truth table if you get stuck.
What is a logic gate made of?
A few transistors.Transistors act like switches with no moving parts.
What does a NAND gate output when A = 1 and B = 1?
0AND would give 1, and NAND is the opposite.
Which gate gives 1 only when the inputs are different?
XOR.
Which register holds the address of the next instruction?
The program counter (PC).
Put the fetch-execute steps in order.
Fetch, decode, get data, execute.
Which memory is volatile: RAM or ROM?
RAM.
What is the fastest level of the memory hierarchy?
Registers.
Chapter 4Operating Systems
What an OS does
Application software does a job for you, like a word processor.
System software runs the computer itself. The OS is system software.
The OS has three jobs:
Manage resources like memory and devices.
Give you a way to use the computer.
Let programs use the computer's resources.
Key words
Word
Meaning
Multiprogramming
Several programs in memory at the same time
Process
A program that is running
CPU scheduling
Picking which process runs next
Real-time system
A system where fast response really matters
Device driver
A small program that knows how to talk to one device
Addresses
A logical address is where something is inside the program.
A physical address is where it really is in memory.
Physical = where the program starts + logical. Program starts at 100, logical is 23, so physical is 123.
Partitions
Fixed partitions split memory into set pieces. Dynamic partitions are made as needed.
The base register holds where the partition starts. The bounds register holds how long it is.
Picking a block
First fit: the first block that is big enough.
Best fit: the smallest block that is big enough.
Worst fit: the biggest block.
Slide example. Blocks: A 1000, B 700, C 750, D 1500, E 300, F 350.
Request
First fit
Best fit
Worst fit
1000
A
A
D
25
A
E
D
780
A
A
D
1300
D
D
D
325
A
F
D
Process states
New: being created.
Ready: waiting for its turn on the CPU.
Running: using the CPU right now.
Waiting: waiting for something else, like a file or the printer.
Terminated: finished.
Lots of processes can be ready or waiting. Only one can be running.
Scheduling
Nonpreemptive: the process gives up the CPU by itself.
Preemptive: the OS takes the CPU away.
Turnaround time: from when a process first shows up to when it finishes.
Algorithm
Rule
Type
First-Come, First-Served
In the order they arrive
Nonpreemptive
Shortest Job Next
Shortest one first
Nonpreemptive
Round Robin
Everyone gets a turn of fixed length
Preemptive
Average turnaround
Add up when each process finishes, then divide by how many there are. Example: P1 = 50, P2 = 20, P3 = 30.
FCFS runs P1, P2, P3. They finish at 50, 70, 100. Average = 220 ÷ 3 = 73.33.
SJN runs P2, P3, P1. They finish at 20, 50, 100. Average = 170 ÷ 3 = 56.67.
Quick check
Use the block list A 1000, B 700, C 750, D 1500, E 300, F 350.
A program starts at 500. A variable has logical address 42. What is its physical address?
542500 + 42.
Best fit for a request of 325?
F (350)E (300) is too small, F is the smallest that fits.
First fit for a request of 780?
A (1000)It's the first block that is big enough.
A process is waiting for the printer. Which state is it in?
Waiting.
Which scheduling algorithm is preemptive?
Round Robin.
Processes A = 30, B = 10 arrive in that order. Average turnaround with SJN?
25B finishes at 10, A at 40. (10 + 40) ÷ 2 = 25.
Chapter 5Networks and Internet
Key words
Word
Meaning
Network
Devices connected so they can share
Node (host)
Any device on the network
Bandwidth
How fast data moves
Latency
The delay before data arrives
Protocol
The rules for how data is sent
Gateway
Connects a LAN to other networks
Router
Sends packets toward where they're going
ISP
The company that gives you Internet
Two ways to set up a network
Client-server: one main server, everyone asks it. Easy to manage, but if the server goes down, everyone is stuck.
Peer-to-peer: every computer is equal and shares directly. No single point of failure, but harder to keep secure.
Sizes of networks
LAN: a small area, like one building.
MAN: a whole city.
WAN: connects LANs far apart.
Internet: a WAN that covers the whole planet.
Packet switching
A message is cut into small numbered packets. Each packet travels on its own. They are put back together at the end.
Protocols to know
Protocol
Job
TCP
Cuts the message into packets and puts them back together
IP
Finds the route for each packet
SMTP
Email
FTP
Sending files
Telnet
Logging into another computer
HTTP
Web pages
The OSI model has 7 layers. A firewall filters traffic to protect a network.
Addresses
A hostname is a name with dots, like www.imamu.edu.sa.
An IPv4 address is 4 bytes (32 bits). They ran out in 2011.
An IPv6 address is 128 bits.
DNS turns a hostname into an IP address.
The TLD is the last part of the name, like .com or .sa.
The Web
The Internet is the network. The Web is the pages and software that run on it. They are not the same.
A browser gets and shows pages. A web server sends them. A URL is the address of a page.
A cookie is a small text file a website saves on your computer. It is not dangerous.
HTML, CSS and XML
HTML builds the page using tags like <body> and </body>.
<head> holds info about the page. <body> holds what you see.
CSS decides how it looks.
XML describes what the data means, and lets you make your own tags.
Cloud and blockchain
Cloud computing: rent computing power and storage over the Internet and pay for what you use (AWS, Google Cloud, Azure).
Blockchain: a shared record of transactions that no single person controls.
Quick check
Last one. You've got this.
Which network type has a single point of failure?
Client-server.
TCP or IP: which one cuts messages into packets?
TCP.IP handles the routing.
Which protocol sends email?
SMTP.
What does DNS do?
Turns a hostname into an IP address.
How many bits are in an IPv4 address? In IPv6?
32 and 128.
Are the Internet and the Web the same thing?
No.The Web runs on top of the Internet.
Which HTML section holds what you see on the page?