Computer Programming Fundamentals (Quick Reference)
Hardware Overview
Hardware refers to the physical components of a computer; a computer is a system of devices that work together.
Major components: central processing unit (CPU), main memory, secondary storage, input devices, output devices.
The CPU
The CPU runs programs; it is the component that actually executes instructions.
History: early CPUs were large electromechanical devices (e.g., ENIAC); today CPUs are microprocessors.
The CPU follows a fetch–decode–execute cycle:
Fetch: read the next instruction from memory into the CPU
Decode: interpret the operation to perform
Execute: perform the operation
A CPU has an instruction set; different CPU brands (e.g., Intel, AMD, Motorola) have different instruction sets.
Main Memory (RAM)
RAM is the computer’s work area; stores a running program and its data.
RAM is volatile: contents are lost when the power is off.
Example: both a word-processing program and the document are in main memory while editing.
Secondary Storage
Non-volatile memory for long-term storage; retains data without power.
Types: disk drives (traditional magnetic), solid-state drives (SSD).
External storage devices (e.g., USB drives) provide backups and data transfer.
Input/Output Devices
Input: keyboards, mice, touchscreens, scanners, microphones, cameras; some storage devices can act as input (loading programs/data).
Output: displays, printers; storage devices can also be outputs when saving data.
Software Overview
System Software: controls basic operations; includes the Operating System (OS), utilities, and software-development tools.
OS examples: Windows, macOS, Linux; mobile OS: Android, iOS.
Application Software: programs that perform everyday tasks (e.g., Word, Excel, web browsers, games).
Data Storage Basics
All data in a computer is stored as binary sequences (0s and 1s).
Memory is organized into bytes; 1 byte = 8 bits; the maximum value in one byte is .
To store larger numbers, use more bytes (e.g., 2 bytes = 16 bits; maximum value ).
Bits, Bytes, and Binary Numbers
A bit is 0 or 1; binary numbers use powers of two.
Bit positions in a byte correspond to (right to left).
Example: the maximum 8-bit value is ; two bytes give 16 bits with maximum .
Storing Characters
Characters are stored as numeric codes, then as binary. ASCII defines codes for English characters and symbols.
ASCII for 'A' is .
Unicode extends encoding to represent many languages; Unicode is becoming the standard.
Number Representation Details
Negative numbers use two’s complement encoding.
Real numbers (floats) use floating-point notation.
These are binary representations that enable storing a wider range of numbers.
Digital Data and Images
Digital data uses binary; images are composed of pixels (picture elements).
Each pixel color is stored as a binary code representing that color.
How a Program Works at the CPU Level
The CPU understands machine language (binary instructions).
To ease programming, assembly language uses mnemonics (e.g., add, mov) and is translated to machine language by an assembler.
High-level languages (e.g., Python) hide CPU details and provide readable syntax.
From Machine Language to Assembly to High-Level Languages
Machine language: binary instructions understood by the CPU.
Assembly language: mnemonics that map to machine instructions; requires an assembler.
High-level languages: allow complex tasks with easier syntax; many languages exist since the 1950s.
Python and Language Concepts
Keywords/reserved words are fixed; operators perform tasks; syntax rules govern code structure.
A program consists of statements written in a high-level language.
Compilers, Interpreters, and Source Code
The CPU executes machine language; translators convert high-level code to machine language.
Compiler: translates a complete high-level program to a machine-language program before execution.
Interpreter: translates and executes instructions on the fly (Python uses an interpreter).
Source code is the programmer’s code; syntax errors prevent translation/execution and yield error messages.
Using Python: Interpreter and Modes
Python is an interpreted language; a Python program can run via an interpreter.
Python comes with IDLE to simplify writing and testing programs.
Modes:
Interactive mode: type statements and execute immediately.
Script mode: run statements from a Python file.
Installing Python (refer to Appendix A in the book) ensures the interpreter is available on your system.