跳到主要内容
英国伦敦 · 创立于 1994 年
中文

Unit 1: How Computers Work

What a computer actually does, how it represents information in binary, and how the processor, memory, storage and operating system cooperate to run programs.

Unit 1 of 5 · about 54 minutes

1.1 Information, binary and data representation

Computer science is the study of computation: how problems can be described precisely, how information can be represented and processed, and how machines can be instructed to carry out that processing reliably. It is broader than programming. Programming is the practical skill of writing instructions; computer science provides the ideas that explain why some instructions work well, why others are slow or fragile, and what computers can and cannot do in principle.

At its simplest, a computer is a machine that takes input, processes it according to stored instructions, keeps results in memory or storage, and produces output. A laptop, a smartphone, a cash machine and the controller inside a washing machine all follow this pattern. What makes a general-purpose computer powerful is that its instructions are themselves data. Load a different program and the same hardware becomes a word processor, a game or a payroll system.

Why binary

Inside a computer, all information is stored and processed as patterns of two states, which we write as 0 and 1. Each 0 or 1 is called a bit (short for binary digit). Two states are used because they are easy to build reliably in electronic circuits: a voltage is either high or low, a tiny switch called a transistor is either on or off. Distinguishing between two states is far less error-prone than distinguishing between ten.

A group of eight bits is called a byte. One byte can hold 256 different patterns (2 multiplied by itself eight times). Larger quantities are described in kilobytes, megabytes, gigabytes and terabytes. Note that you will see two conventions: some contexts treat a kilobyte as 1,000 bytes and others as 1,024 bytes. Operating systems and storage manufacturers do not always agree, which is one reason a new drive can appear smaller than advertised.

Counting in binary

In everyday decimal numbers, each position is worth ten times the one to its right: units, tens, hundreds. In binary, each position is worth twice the one to its right: 1, 2, 4, 8, 16 and so on. The binary number 1011 therefore means one 8, no 4, one 2 and one 1, which is 11 in decimal. You do not need to convert numbers by hand in most jobs, but understanding the principle explains a great deal, such as why many limits in computing are powers of two.

Representing everything else

If everything is bits, how does a computer store text, pictures or sound? The answer is agreed encodings: shared rules that say which pattern of bits stands for what.

  • Text is stored by giving every character a number. Early systems used ASCII, which covered English letters, digits and punctuation. Today most systems use Unicode, a standard that covers the scripts of almost every written language, together with an encoding such as UTF-8 to turn those numbers into bytes.
  • Images are usually grids of tiny dots called pixels, with each pixel's colour stored as numbers, commonly amounts of red, green and blue.
  • Sound is recorded by measuring the height of the sound wave many thousands of times per second and storing each measurement as a number.
  • Numbers with fractions are stored in a format called floating point, which is very flexible but can only approximate many values. This is why some programs show 0.1 plus 0.2 as 0.30000000000000004.

The same bit pattern can mean completely different things depending on which encoding is applied. A file is only meaningful when the program reading it knows how it was written. This is the root of many everyday problems, from garbled characters in an imported spreadsheet to a document that will not open in the wrong application.

Remember: Bits have no meaning on their own. Meaning comes from the agreed encoding used to write and read them.

Compression

Because data can be large, computers often compress it. Lossless compression, used in formats such as ZIP and PNG, lets the original be rebuilt exactly. Lossy compression, used in formats such as JPEG and most streaming audio and video, discards detail that people are unlikely to notice in exchange for much smaller files. Repeatedly editing and re-saving a lossy file can gradually reduce its quality.

In practice

These ideas have direct workplace uses. When names with accents appear as strange symbols after a data import, the likely cause is a text encoding mismatch, and choosing UTF-8 when exporting and importing usually fixes it. When financial figures in a spreadsheet differ by a tiny fraction, floating-point approximation may be the reason, and rounding rules or dedicated decimal formats are the remedy. When deciding how to store scanned contracts, knowing the difference between lossless and lossy formats helps you avoid losing detail you may later need.

1.2 Inside the machine: processor, memory and storage

Most computers in use today follow a design described in the 1940s and usually called the von Neumann architecture, after the mathematician John von Neumann. Its central idea is that both the program and the data it works on are held in the same memory. The processor fetches instructions from memory one after another, works out what each one means and carries it out. Understanding the main parts of this design helps you make sense of specifications, performance problems and many technical conversations.

The central processing unit

The central processing unit (CPU), or processor, carries out instructions. Each instruction is very simple: add two numbers, compare two values, copy a value from one place to another, or jump to a different instruction if a condition is met. The processor repeats a basic cycle known as fetch, decode, execute:

  1. Fetch the next instruction from memory.
  2. Decode it to work out which operation is needed and on what data.
  3. Execute it, for example by performing a calculation, and store the result.

The processor keeps a small number of very fast storage locations called registers, including one that records the address of the next instruction. Its speed is partly described by the clock rate, measured in gigahertz, which indicates how many cycles it can perform each second. Modern processors also have several cores, each able to run instructions independently, so a computer can work on several tasks at the same time. Clock rate and core count are only rough guides to real performance, because design details matter a great deal.

Memory and storage

It is important to distinguish two kinds of storage that are often confused.

FeatureMain memory (RAM)Storage (SSD or hard disk)
PurposeHolds programs and data currently in useKeeps files and programs long term
SpeedVery fastMuch slower than RAM
When power is offContents are lost (volatile)Contents are kept (non-volatile)
Typical sizeGigabytesHundreds of gigabytes to terabytes

When you open a document, it is copied from storage into memory so that the processor can work on it quickly. When you save, the changes are written back to storage. This is why unsaved work can be lost in a power cut: it existed only in memory.

The memory hierarchy

There is a trade-off between speed, size and cost. The fastest storage is small and expensive; the largest is slower and cheaper. Computers therefore use a memory hierarchy: registers, then several levels of cache built into the processor, then main memory, then solid-state drives or hard disks, and finally network or cloud storage. Data that is used often is kept as close to the processor as possible. A great deal of performance engineering comes down to making sure the right data is in the faster layers at the right time.

Tip: If a computer slows down badly when many applications are open, it may be running out of memory and moving data to and from much slower storage. Adding memory or closing programs often helps more than a faster processor.

Input, output and buses

Keyboards, touchscreens, microphones, cameras and sensors provide input; screens, speakers and printers provide output. Network adapters do both. The components communicate over connections called buses and through controllers that manage particular devices. Graphics processing units (GPUs), originally designed to draw images, contain many simple cores working in parallel and are now widely used for scientific computing and machine learning.

Common misunderstandings

  • "More gigahertz always means faster." Not necessarily: newer designs often achieve more per cycle.
  • "Storage and memory are the same." They are not, and they solve different problems.
  • "A slow computer needs replacing." Often the bottleneck is one component, such as insufficient memory or an old hard disk.

In practice

When comparing laptops for a team, look at the workload first. Office work and video calls benefit most from adequate memory and a solid-state drive. Data analysis may need more memory and cores. Design and machine-learning work may need a capable GPU. When users report that a system is slow, ask what they were doing, how many applications were open and whether the storage is nearly full; the answers usually point to the bottleneck.

1.3 Operating systems and how programs run

Hardware alone cannot do anything useful for most people. Between the hardware and the applications you use sits the operating system (OS). Well-known families include Windows, macOS, Linux, Android and iOS. Although they look different, they perform the same core jobs, and understanding those jobs explains much of what you see when using a computer or managing systems at work.

What an operating system does

  • Process management. A running program is called a process. The OS starts and stops processes and decides which one runs on each processor core at any moment.
  • Memory management. The OS gives each process its own area of memory and prevents processes from interfering with one another's data.
  • File systems. The OS organises storage into files and folders, keeps track of where each file's data physically sits and records information such as names, sizes and permissions.
  • Device management. Through small programs called drivers, the OS talks to printers, displays, network cards and other hardware, so that applications do not need to know the details of each device.
  • Security and users. The OS manages user accounts, logins and permissions, deciding who may read, change or run each file.
  • User interface. The OS provides a graphical desktop or touch interface, and usually a text-based command line as well.

The innermost part of the OS, which has full control of the hardware, is called the kernel. Applications run with fewer privileges and must ask the kernel to perform sensitive actions, such as reading a file or sending data over a network. These requests are called system calls. This separation is a key security feature: a faulty or malicious application should not be able to take over the whole machine.

Multitasking and scheduling

A typical computer may have hundreds of processes running, far more than it has processor cores. The OS creates the impression that they all run at once by switching between them many times per second, a technique called time-sharing. The part of the OS that decides which process runs next is the scheduler. It tries to keep interactive programs responsive while still giving background tasks a fair share. Within a process, work can be split into threads, which share the same memory and can run on different cores at the same time.

Virtual memory

Each process behaves as if it has a large, private block of memory. In reality, the OS maps this virtual memory onto physical memory, and can temporarily move parts that are not in use to storage. This makes programs simpler to write and keeps them isolated, but heavy use of storage in place of memory, often called swapping or paging, can slow a system dramatically.

From source code to running program

Programmers usually write in a high-level language such as Python, Java, C# or JavaScript, which is designed to be readable by people. The processor understands only machine code, its own set of binary instructions. Two broad approaches bridge the gap:

  • A compiler translates the whole program into machine code (or a lower-level form) before it runs. Compiled programs typically run quickly.
  • An interpreter reads and carries out the program step by step as it runs, which makes experimenting easier but can be slower.

Many modern languages combine the two, compiling to an intermediate form and then optimising it while the program runs.

Remember: When an application "freezes", the operating system is usually still working. Task Manager on Windows, Activity Monitor on macOS and similar tools on Linux let you see which process is using the processor or memory and close it safely.

Virtual machines and containers

A virtual machine is software that imitates a complete computer, so one physical server can run several operating systems side by side. A container is a lighter approach: applications share the host's kernel but are packaged with everything else they need, so they behave the same on a developer's laptop and on a cloud server. Both ideas underpin modern cloud computing.

In practice

Understanding the OS helps with everyday troubleshooting. If a program cannot open a file, check permissions before assuming the file is damaged. If a device stops working after an update, a driver is a likely cause. If a server is slow, look at which processes are consuming processor time and memory. When colleagues talk about "deploying a container", you will know that they mean packaging an application with its dependencies so it runs consistently anywhere.

Case study: Diagnosing a slow reporting laptop at a charity

Greenway Housing Trust, a fictional housing charity, issued its finance officer a laptop to prepare monthly reports. Every month-end the laptop became almost unusable, and the officer assumed it needed replacing. Before buying new equipment, the trust's part-time IT volunteer investigated.

Opening the system's activity monitor during a slow period showed that the processor was mostly idle, but memory was full. The reporting spreadsheet, a browser with dozens of tabs and a video-call application were together using more memory than the laptop had, so the operating system was constantly moving data to and from the storage drive. The drive itself was an older hard disk, which made this paging very slow.

The volunteer recommended two inexpensive changes: adding memory and replacing the hard disk with a solid-state drive. She also showed the officer how to close unused tabs and check memory use. Month-end reporting time dropped noticeably, the laptop remained in service for another two years, and the trust adopted a simple rule of checking for the actual bottleneck before replacing any computer.

Activity

Open the activity or task monitor on a computer you use and note the three processes using the most memory and the three using the most processor time. For each, write down what it is and whether it surprised you. Then look up how much memory and what type of storage the computer has, and explain which component would most likely limit its performance for your typical work.

Compare with a model answer

A good answer names specific processes, such as a web browser, an email client and a video-call application, and records approximate figures rather than vague impressions. It notes that a browser often appears as many separate processes because each tab or extension may run in its own process for stability and security.

It then states the installed memory, for example 8 GB, and the storage type, such as a solid-state drive. The explanation links these facts to the workload: if memory use is regularly close to the total, memory is the likely bottleneck; if the processor is often near full use during calculations, more or faster cores would help; if the machine still uses a hard disk, storage speed may limit start-up and file opening. The strongest answers suggest a specific, proportionate improvement.

Key takeaways

  • Computers represent all information as bits, and meaning comes from agreed encodings such as Unicode for text.
  • The processor repeatedly fetches, decodes and executes simple instructions held in memory alongside data.
  • Memory is fast but temporary; storage is slower but permanent, and the memory hierarchy balances speed, size and cost.
  • The operating system manages processes, memory, files, devices and security, with the kernel protecting the hardware from applications.
  • Compilers and interpreters translate human-readable code into instructions the processor can carry out.

Unit check

Create a free account to answer the check, save your progress and receive your free certificate.

Create a free account Log in
← Course overview Unit 2 →
WhatsApp