Computer science 🤮
Chapter 1: Data Representation - Detailed Notes
1.1 Number Systems
Binary System
Definition: Base 2 number system using only 0 and 1
Why computers use binary: Computers contain millions of
switches that can only be ON (1) or OFF (0)
Column headings: Powers of 2 (2⁰, 2¹, 2², 2³, etc. = 1, 2, 4, 8, 16,
32, 64, 128...)
Converting Between Number Systems
Binary to Denary
Add column values where 1 appears
Example: 11101110 = 128 + 64 + 32 + 8 + 4 + 2 = 238
Denary to Binary (Two Methods)
Method 1 - Successive Subtraction:
Subtract largest possible power of 2 repeatedly
Example: 142 = 128 + 14, 14 = 8 + 6, 6 = 4 + 2, 2 = 2
Result: 10001110
Method 2 - Successive Division:
Divide by 2, record remainder, continue until result is 0
Read remainders from bottom to top
Hexadecimal System
Base 16 system using digits 0-9 and letters A-F (A=10, B=11,
C=12, D=13, E=14, F=15)
Relationship to binary: 4 binary digits = 1 hex digit (since 16 =
2⁴)
Column headings: Powers of 16 (16⁰, 16¹, 16², 16³, etc.)
Converting Binary to Hex
Group binary digits in sets of 4 (from right to left)
Convert each group to its hex equivalent
Example: 101111100001 → 1011 1110 0001 → B E 1
Converting Hex to Binary
Convert each hex digit to its 4-bit binary equivalent
Join all groups together
Uses of Hexadecimal
1. Error codes: Memory locations of errors shown in hex
2. MAC addresses: Format NN-NN-NN-DD-DD-DD (manufacturer code
- device code)
3. IP addresses: IPv6 uses 128-bit addresses in hex format
4. HTML color codes: #RRGGBB format (red, green, blue values)
Binary Addition
Rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (0 with carry 1)
Overflow: When result exceeds maximum bits available
Example: 8-bit maximum = 255 (2⁸-1)
Logical Binary Shifts
Left shift: Equivalent to multiplying by 2
Right shift: Equivalent to dividing by 2
Empty positions filled with zeros
Limitation: Bits can be lost, causing errors
Two's Complement
Purpose: Represent negative numbers in binary
Method: Left-most bit becomes negative weight
For 8-bit: -128, 64, 32, 16, 8, 4, 2, 1
Converting to Two's Complement
Method 1: Use negative column values directly
Method 2:
1. Write positive binary
2. Invert all bits (0→1, 1→0)
3. Add 1
1.2 Text, Sound and Images
Character Sets
ASCII Code
7-bit system (0-127 in denary, 00-7F in hex)
Extended ASCII: 8-bit (0-255), includes non-English characters
Limitations: Only Western languages, inconsistencies between
systems
Unicode
Purpose: Represent all world languages
Capacity: Up to 4 bytes per character
Compatibility: First 128 characters same as ASCII
Goals: Universal standard, efficient coding, uniform encoding,
unambiguous, private use area
Sound Representation
Analogue to Digital: Sound waves are continuous (analogue),
must be converted to digital
Sampling: Measuring amplitude at regular intervals using ADC
Sampling rate: Number of samples per second (Hz)
Sampling resolution (bit depth): Number of bits per sample
CD quality: 16-bit resolution, 44.1 kHz sampling rate
Effects of Higher Sampling
Benefits: Better quality, larger dynamic range, less distortion
Drawbacks: Larger file sizes, longer transmission times, more processing
power needed
Image Representation
Bitmap images: Made of pixels (picture elements)
Color depth: Number of bits per pixel
o 1 bit = 2 colors (black/white)
o 8 bits = 256 colors
o 24 bits = 16.7 million colors (8 bits each for RGB)
Image resolution: Number of pixels in image (e.g., 4096 × 3072)
Trade-off: Higher resolution = better quality but larger file size
1.3 Data Storage and File Compression
Memory Measurement
Binary-based (IEC Standard)
1 KiB = 2¹⁰ = 1,024 bytes
1 MiB = 2²⁰ = 1,048,576 bytes
1 GiB = 2³⁰ = 1,073,741,824 bytes
1 TiB = 2⁴⁰ bytes
File Size Calculations
Image Files
Formula: Resolution (pixels) × Color depth (bits) ÷ 8 (for bytes)
Example: 2048 × 2048 pixels, 16-bit color = 8 MiB
Sound Files
Mono: Sample rate (Hz) × Sample resolution (bits) × Length (seconds) ÷
8
Stereo: Multiply result by 2
Data Compression
Reasons for compression:
Save storage space
Reduce transmission time
Reduce bandwidth usage
Lower costs
Lossy Compression
Characteristic: Original cannot be fully restored
Examples: JPEG (images), MP3/MP4 (audio/video)
JPEG method: Reduces data based on eye's sensitivity to
brightness vs. color
MP3 method: Removes sounds human ear cannot detect
(perceptual music shaping)
Lossless Compression
Characteristic: Original can be fully restored
Method: Run Length Encoding (RLE)
Run Length Encoding (RLE)
Process: Replace repeated data with count + value
Example: "aaaaabbbb" → "5a4b"
Effectiveness: Best with long runs of identical data
Flags: Used to handle mixed data efficiently
Chapter 2: Data Transmission - Detailed Notes
2.1 Types and Methods of Data Transmission
Data Packets
Definition: Small pieces of data (typically 64 KiB) sent over
networks
Benefits: Each packet can take different routes, easier to control
than continuous stream
Drawback: Need to reassemble at destination
Packet Structure
Header contains:
Source IP address
Destination IP address
Sequence number (for reassembly)
Packet size
Payload: Actual data (~64 KiB)
Trailer contains:
End-of-packet identifier
Error checking (Cyclic Redundancy Check - CRC)
Packet Switching
Process: Message broken into packets, each sent independently
Routing: Routers determine best path for each packet
Reassembly: Packets may arrive out of order, must be reordered
Benefits of Packet Switching
No single communication line tied up
Can overcome failed/busy lines
Easy to expand
High data transmission rates
Drawbacks
Packets can be lost
Prone to errors in real-time streaming
Delay at destination during reassembly
Hop Numbers
Purpose: Prevent packets from bouncing endlessly
Method: Number decreases by 1 at each router
Action: Packet deleted when hop number reaches 0
Data Transmission Types
Direction of Transmission
1. Simplex: One direction only (computer → printer)
2. Half-duplex: Both directions, not simultaneously (walkie-talkie)
3. Full-duplex: Both directions simultaneously (broadband internet)
Method of Transmission
1. Serial: One bit at a time over single channel
o Good over long distances
o Slower than parallel
o Data remains synchronized
2. Parallel: Multiple bits simultaneously over multiple channels
o Faster transmission
o Good for short distances only
o Data can become skewed over long distances
Universal Serial Bus (USB)
Cable: 4-wired shielded cable (power + data)
Auto-detection: Computer automatically detects device
Driver loading: Appropriate software loaded automatically
Data transmission: Supports half-duplex and full-duplex
Benefits of USB
Automatic detection and driver loading
Industry standard
Various data rates supported
Built-in power supply
Error detection and retransmission
Backward compatible
Drawbacks
Limited cable length (5m maximum)
Slower than some alternatives (Ethernet)
Older standards may not be supported
2.2 Methods of Error Detection
Need for Error Checking
Errors can occur due to:
Electrical interference
Packet switching problems
Data skewing (parallel transmission)
Problem: Computers cannot understand corrupted text that humans
might still read
Error Detection Methods
Parity Checks
Principle: Based on number of 1-bits in byte
Even parity: Even number of 1-bits
Odd parity: Odd number of 1-bits
Parity bit: Added to make byte conform to chosen parity
Detection: Error flagged if received byte has wrong parity
Parity Blocks
Method: Check parity horizontally AND vertically
Advantage: Can identify exact location of single-bit error
Process: Find intersection of incorrect row and column
Checksum
Process:
1. Calculate checksum from data block using agreed algorithm
2. Send checksum with data
3. Receiver recalculates checksum
4. Compare values - if different, request retransmission
Echo Check
Method: Data sent back to sender for comparison
Problem: Can't tell if error occurred during send or return
Reliability: Less reliable than other methods
Check Digits
Purpose: Detect data entry errors (not transmission errors)
Location: Final digit of code
Detects: Incorrect digits, transposition errors, missing/extra digits
ISBN-13 Method
1. Add odd-positioned digits
2. Add even-positioned digits, multiply by 3
3. Add results, divide by 10
4. If remainder = 0, use 0; otherwise subtract remainder from 10
Modulo-11 Method
1. Assign weightings (8,7,6,5,4,3,2) from left
2. Multiply digits by weights, sum results
3. Divide by 11
4. Subtract remainder from 11 (use X if remainder = 10)
Automatic Repeat Requests (ARQs)
Components: Positive/negative acknowledgments, timeout
Process:
1. Receiver checks data using error detection
2. Sends positive ACK if correct, negative ACK if error
3. Sender waits for acknowledgment within timeout period
4. Retransmits if no ACK received within timeout
Usage: Common in mobile phone networks
2.3 Symmetric and Asymmetric Encryption
Purpose of Encryption
Goal: Make intercepted data unreadable
Terms:
o Plaintext: Original readable data
o Ciphertext: Encrypted unreadable data
Limitation: Doesn't prevent interception, just makes data
meaningless
Symmetric Encryption
Characteristic: Same key for encryption and decryption
Key strength: Modern systems use 256-bit keys (2²⁵⁶
combinations)
Main problem: Key distribution - how to securely share the key
Asymmetric Encryption
Innovation: Uses two related keys (public and private)
Public key: Made available to everyone
Private key: Kept secret by owner
Process
1. Recipient generates matching key pair
2. Recipient sends public key to sender
3. Sender encrypts message with recipient's public key
4. Recipient decrypts with their private key
Advantages
Security: No need to share secret keys
Scalability: One person can receive from many senders
Two-way communication: Each person needs their own key pair
Mathematical Relationship
Keys are mathematically linked but cannot be derived from each
other
Public key can only encrypt, private key can only decrypt matching
messages