Version To Share - IGCSE Computer Science Notes (Full V)
Version To Share - IGCSE Computer Science Notes (Full V)
Binary shift
- Left shift → multiples number by 2
- Right shift → divides number by 2
- Eg) 1101 1001 (217) → right shift → 0110 1100 (108)
- The least significant bit was storing 1. When the right shift occurs this information is lost, resulting in the
number being rounded down & 0.5 is lost
Two’s complement (for negative numbers)
- In 8 bit register, the most significant bit is given the value -128
-128 64 32 16 8 4 2 1
- No difference for positive binary numbers
- Positive → Negative
- Eg) 0010 1011 (43)
- Convert everything (0 → 1, 1 → 0) → 1101 0100
- Add 0000 0001 → 1101 0101 (-43)
- Sound file size (bits) = Sample rate (Hz) x resolution (bits) x duration (s)
- 2 channel = file size x 2
- Image file size = resolution x colour depth
Compression → to reduce size of file
- Necessary to reduce file size because…
- Less bandwidth required, less storage space required, shorter transmission time
- Lossless compression → reduces file size without permanent loss of data (eg. RLE, PNG))
- Run length encoding (RLE)
- Eg) 1 = white, 0 = black
4 ‘1’s and 12 ‘0’s → 4 1 12 0
- First value: number of identical data items / Second value: code of data item
- Effective only when there is long run of repeated units
- Lossy compression → reduces file size by permanently removing data (eg. JPEG, mpeg-3)
- Benefits & drawbacks of increasing sampling rate & resolution
- Benefits
- Larger dynamic range
- Better sound quality
- Less sound distortion
- Drawbacks
- Produce larger files
- Takes longer to transmit / download
- Requires greater processing power
2 Data transmission
2.1 Types and methods of data transmission
- Data broken down into packets to be transmitted
Structure of packet
- Header → destination address + originating address + packet number
- Payload → contents that need to be sent = actual data
- Trailer → data indicating end of packet + checksum
Process of packet switching
- Data broken down into packets
- Each packet could take different route
- Router controls route a packet takes
- Packets may arrive out of order
- Once the last packet has arrived, packets are reordered
Data transmission
- Crosstalk : signal on one line creates disturbance in another line → cause bits to be reversed
- Skew : signals arrive at slightly diff times because cables have slightly diff properties → receiver needs
to wait until all lines are received
Benefits Drawbacks
Connected to all devices by simply installing drivers Connections should be 5 m in length before USB hub
is used
Can support different data transmission rates
Data transfer speeds not fast enough to use in internal
No need for external power
devices (CPU, hard drive)
2.2 Methods of error detection
- Transmission errors due to…
- Electrical interference, power surges, synchronisation issues, wear and tear on connector cables
- Errors may cause… data loss, data gain, data change
Error detection
- Parity bit check
- Used to check if there is an error in transmission
- Even parity → total number of 1s must add to an even number
- Odd parity → total number of 1s must add to an odd number
- On every chunk (or byte) sent → parity digit added
- Example in even parity
- If even → parity bit will become 0 to make # of 1s even
- If odd → parity bit will become 1 to make # of 1s even
- If parity bit fails → sender gets notified by receiver + data resent
- Drawback: cannot find exactly which bit is in error
- Parity block check
- Can find which row and column the error is in → can find exact place & correct the bit
- Drawback: cannot detect error if 2 or more number of bits has changed
- Check digits
- Additional digit at the end of set of numbers to check for mistakes in input or transmission
- Receiver notices error → will notify sender
- Eg) ISBN, barcodes
- Check sum
- Created and sent with file
- When received → checksum generated again + compared
- If doesn’t match → file may have been corrupted or altered
- Used for security → downloading softwares + processing credit card
- Echo check
- Data transmitted to receiver
- Same data echoed back to transmitter
- Transmitter compares data with original
- If not the same → data transmitted again
- Drawback: if wrong data received → cannot know if error occurred when sending data at first
or when sending data back to sender for checking
- Automatic Repeat Request (ARQ)
- At transmission, timer starts → sender sends data → receiver sends acknowledgement
- When sender receives acknowledgement → sends next data
- If acknowledgement not received → timeout occurs + data resent
- Positive acknowledgement : when data correctly received → acknowledgement (ACK) sent
- Negative acknowledgement : when receiver detects error in data → negative acknowledgement
(NACK) sent
- Sender doesn’t need to wait in timeout → can immediately resend data
2.3 Encryption
Purpose of encryption when transmitting data
- Encode file or data into something that cannot be read or understood
- Key or password used to decrypt data
- Encrypt → encode into unreadable form
- Decrypt → decode encrypted data back into plaintext
Symmetric encryption
- Key first shared between sender and receiver
- Key encrypts data before transmission → receiver uses key to decrypt data
Asymmetric encryption
- Two keys created by the receiver
- Public key → accessible by anyone and used to encrypt data (shared with sender)
- Private key → kept secret by the receiver and used to decrypt data
- Anyone can encrypt data, but only the receiver can decrypt it
- No need to share a secret key like symmetric encryption
Web asymmetric encryption
- Web pages shared using HTTPS → makes use of encryption
- Browser + server share necessary public keys to encrypt data & use private keys to decrypt data
- If symmetric encryption is used → every website would have to send password privately to you
3 Hardware
3.1 Computer architecture
Central processing unit (CPU) → processes instructions and data that are input so that result can be output
Microprocessor → type of integrated circuit on a single chip
Von Neumann architecture → instructions and data both in same memory (CPU accesses both from same RAM)
RAM → holds all data and programs needed to be accessed by CPU
- CPU takes data and programs held in the backing store and puts them into RAM temporarily (bc.
read/write operations faster in RAM than in backing store)
Components of CPU
Units
Allows required arithmetic (+, -, shifting) & logic operations (AND, OR, NOT) to be
Arithmetic &
carried out
Logic Unit (ALU)
Possible to have more than one ALU to carry out specific functions
Current instruction
Stores current instruction being decoded and executed
register (CIR)
Accumulator
Used when carrying out ALU calculations → stores data temporarily during calculations
(ACC)
Memory address
Stores address of memory location currently being read from or written to
register (MAR)
Memory data Stores data which has just been read from memory or data which is about to be written
register (MDR) to memory
Program counter
Stores address where next instruction to be read can be found
(PC)
Buses → collection of wires through which data or control signals are transmitted
Carries data from CPU to memory (+ vice verse) and to & from input/output devices
Data = address, instruction, numerical value
Data bus
Bidirectional (data sent in both directions)
Wider bus → larger word length can be transported → improve performance
Carries signals from control unit to other components → control activities within CPU
Control bus
Unidirectional or bidirectional
Fetch-Decode-Execute cycle
- Fetch → fetch instruction and data involved from main memory
- Decode → instruction decoded so that it can be interpreted
- Execute → CPU passes decoded instruction as control signals
- Steps:
- PC contains address of memory location of next instruction which has to be fetched
- Address copied from PC to MAR by address bus
- Contents/instructions at memory location contained in MAR copied temporarily into MDR
- Contents/instructions of MDR copied into CIR
- Value in PC incremented by 1 → for next instruction to be fetched
- Instruction decoded and executed in ACC by sending out signals by control bus to components
Factors that affect performance of CPU
- Number of cores
- Cores → processing units placed in one CPU (한번에 instruction을 몇개나 처리할 수 있는지)
- One core made up of ALU + control unit + registers
- Using more cores → more need to continually increase clock speeds
- BUT double number of cores doesn’t double performance (케바케)
- Size of cache
- Cache → very fast, expensive memory in CPU (RAM < cache < register)
- Stores frequently used instructions and data → improve CPU performance
- Larger cache memory size → better CPU performance
- Level 1, 2, 3 cache (faster levels tried first)
- Reduces time that CPU has to wait for data from main memory
- Speed of clock
- Clock → cycles per second measured in hertz (Hz)
- Increasing clock speed → increase in processing speed (not necessarily increase in
overall performance)
- Overclocking (clock speed higher than computer designed for)
- Unsynchronised operations (crash + unstable) + overheating
Instruction set → list of all commands that can be processed by CPU
- CPU uses assembly code or machine (binary representation of assembly code) code
- Opcode → informs CPU what operation needs to be done (instructions)
- Eg) STO = store
- Operand → data which needs to be acted on or register in memory (values worked on)
- Eg) 057 = into memory address 057, ACC = contents of accumulator
Embedded system
- Combination of hardware and software designed to carry out specific functions
Benefits Drawbacks
- Small in size → easy to fit into devices - Difficult to upgrade = more thrown
- Relatively low cost to make away than repaired
- Usually dedicated to one task = simple interfaces - Although interface seems more simple,
- Consume very little power actually more confusing
- Very fast reaction to changing input - Can be accessed over internet = open to
- Mass production → reliability hackers / viruses
- Different to general purpose computers that is used to perform many different functions
- PC or laptop NOT embedded system
- Examples
- Cars → GPS system, entertainment systems, airbags, fuel injection system, exhaust emissions,
vehicle security, ABS braking
- Security systems → temperature/pressure/acoustic input, interface remotely
- Lighting systems → Use inputs & data stored considering different factors (eg. time)
- Vending machines → input pad for selection, coin counter, temperature sensors
- Washing machines → keypad or dials for selection
- Plastic keys + small pieces of rubber under key → make key bounce back up
Keyboard
- Key pressed → make contact with conducting membrane
2D scanners - Used to input hard copy (paper) documents → convert into electronic form
Capacitive - Composed of layers of glass + electrostatic field change when touched by bare
fingers (bc. human skin is conductor)
- Microcontroller calculate position of change → calculates coordinates
Advantages Disadvantages
- Good visibility in strong sunlight - Only work w. bare fingers or special stylus
Capacitive - Durable screen - Sensitive to electromagnetic radiation
- High scratch resistance (magnetic fields or microwaves)
- Multi-touch facility
- Sensitive to water or moisture
- Good durability
Infrared - Accidental activation if beams disturbed
- Operability not affected by
- Sensitive to light interference
scratched or cracked screen
Output devices
- Produce sound → digital data (binary) changed into analogue data (electric
(Loud) Speaker
current) by DAC + passed through amplifier + loudspeaker converts into sound
Light projectors
Digital light - Mirror for each pixel, rotating wheel RGB (changing colour very quickly)
processing - Adv → high contrast ratio, high longevity, quiet running, small + light
projector (DLP) - Disadv → bad colour saturation, ‘shadows’ when showing moving image
Liquid crystal - 3 LCD screens for RGB, reflected lights (in diff wavelength) all combined by prism
display projector - Adv → sharp image, good colour saturation, efficient energy use, less heat
(LCD) - Disadv → bad contrast ratio, bad longevity (degrade with time)
Screens
Light emitting - Varying electric current sent to each LED → diff brightness → range of colours
diodes (LED) - Uses → large outdoor displays
screen - Adv → brilliance of colours, less power + cost, sharp image, last indefinitely
Liquid crystal - Tiny liquid crystals making up array of pixels affected by changes in electric fields
display (LCD) - Uses → small electronic device + cheap TV (X need good quality display)
screen - Adv → low manufacturing cost
Printer
Advantages Disadvantages
Laser printer - Large toner cartridges + paper trays - Maintenance costly due to fusers +
(large amount, - Cost per page less (cost effective) large toner cartridges
less quality) - Quiet - Larger in size
Sensor → input devices which read or measure physical properties from surroundings (in analogue form)
Acoustic (sound) Convert detected sound into electric signals/pulses (noise of footsteps in security system)
Accelerometer Measure acceleration and motion of application (measure rapid deceleration for air bags)
Flow (rate) Measure flow rate of moving liquid or gases (respiratory devices in hospitals)
Gas O2 and CO2 sensors + produce output based on gas levels (monitor pollution levels in air)
Invisible beam of infrared radiation → something breaks beam = diff amount of radiation
Infra-red
reaching detector (security alarm system detecting body heat)
Level Detect changing liquid lvl + measure static conductivity (monitor level in petrol tank in car)
Light Use photoelectric cells that produce output depending on brightness (street lights)
Magnetic field Measure changes in magnetic fields (anti-lock braking systems in cars)
Moisture Measures water levels based on elec. resistance (monitor moisture in soil in greenhouse)
Pressure Generates different electric currents depending on pressure (detect weight of intruder)
Proximity Detect presence of nearby object (mobile phone screen switching off when held to ear)
Volatile memory (data lost without power) Non-volatile (data not lost even without power)
- Secondary storage
- Not directly accessed by CPU + necessary for more permanent storage of data
- Non-volatile (data not lost even without power)
- Can be external or internal to computer
- Uses : Hard drive, blu-ray, memory stick, SD card
- Eg) HDD, SSD
Software
Virus check Constantly check for virus by heuristic checking → quarantine → delete
Files saved to magnetic hard disk (in next available space) → drive head moves more = slow
Disk
Defragmenter puts files into contiguous sectors → reduce head movement = fast access
defragmentation
Not used in SSD because → SSD already quick
Back up Allow schedule for backing files to be made - only if changes were made
Security software Manage access control & user accounts (ID + PW)
Screensavers Supply images on monitor after period of inactivity → automatically logs out (secure)
Communicate with OS & translate into format understood by hardware peripheral device
Device driver
- Descriptors : info about device (vendor ID, product ID, serial number)
Handling interrupts
Providing an interface Allows user to tell computer what to do (GUI, CLI, wimp)
Managing peripherals and drivers Peripheral devices need device drivers (allows OS to access device)
Managing memory Keeps record of where each program & data is stored
Providing platform for running applica. When program opened → OS loads program into RAM
Providing system security Users checked by passwords, access restricted, files protected
4.2 Types of programming language, translators and integrated development environment (IDEs)
- High-level language : independent of computer hardware
- Low-level language : dependent of computer hardware
- Machine code (binary instructions) + assembly language (translated into machine code)
- Larger programs
- Independent of type of computer being used
- Take longer to execute
High-level - Easier to R, W, U (language closer to English)
- X able to make use of
- Easier + quicker to debug
special hardware
Assembly languages
- Form of low-level language that uses mnemonics
- Mnemonics to represent each opcode + denary number or identifier for operand
- Translates high level language program into - Translates whole code at once before
machine code executing it
- Executes code line-by-line - Produces executable file
- Error detected → displays error message + - Errors detected → error report for whole
stops execution code produced instead of compiled program
- Slower execution (bc. every line translated - Fast execution (bc. whole program ready to
before execution) be executed)
- Cannot run without interpreter - Executed without compiler
- Easy to edit programs + debug and test - Take less space
- Faster when developing program (bc. no - Used when : translating final program
need to compile whole program) - Take time if carried out during development
Threats
Virus Worm
Pharming Phishing
- Control amount of personal info shared - Ensures that software systems are uptodate
VPN Proxy-server
Advantages Disadvantages
- Cost-effective → help reduce labour costs in - Unemployment → lead to job loss in certain
long run industries
- Uses program specification from analysis stage to show how program should be developed
Design
- Decomposition, structure diagrams, flowcharts, pseudocode
- Testing program code with use of test data → to make sure that it works under all
Testing
conditions
Begin / End
Process Input / Output Decision Flowline
(Terminator)
Flowcharts
Totalling Counting
Keeping a total that values are added to Keeping number of times of an action is performed
PassCount ← 0
FOR Counter ← 1 TO ClassSize
INPUT StudentMark
IF StudentMark > 50
THEN
PassCount ← PassCount + 1
Total ← 0 ENDIF
FOR Counter ← 1 TO ClassSize NEXT Counter
Total ← Total + StudentMark[Counter] Count ← Count + 1
NEXT Counter
Counting until a certain value:
NumberInStock ← NumberInStock - 1
IF NumberInStock < 20
THEN
CALL Reorder()
Max ← StudentMark[1] // set min and max as first item in the list
Min ← StudentMark[1]
FOR Counter ← 2 TO ClassSize
IF StudentMark[Counter] > Max
THEN
Max ← StudentMark[Counter] Total ← 0
ENDIF
Count ← 0
IF StudentMark[Counter] < Min
THEN Average ← 0
Min ← StudentMark[Counter] WHILE SushiDetected
ENDIF
Total ← Total + Price
NEXT Counter
Count ← Count + 1
Example - Only finding min or max: ENDWHILE
Min ← 0 Average ← Total / Count
First ← TRUE
OUTPUT Average
WHILE SushiDetected
IF First THEN
Min ← Price
ELSE
First ← FALSE
IF Price < Min THEN
Min ← Price
Value between upper value & lower value Contains exact number of characters (eg. 8 char)
- Eg) % marks between 0 and 100 inclusive OR is a reasonable number of characters (2~30 char)
ValidNameLength ← FALSE
ValidAge ← FALSE
Name ← ""
Age ← 0
WHILE NOT ValidNameLength DO
WHILE NOT ValidAge DO
INPUT Name
INPUT Age
IF LENGTH(Name) >= 8
IF Age >= 0 AND Age <= 120 THEN
THEN
ValidAge ← TRUE
ValidNameLength ← TRUE
ENDIF
ENDIF
ENDWHILE
ENDWHILE
Data entered is a given data type Some data has been entered & not been left blank
- Eg. Number of siblings = integer - Eg. Email address must be completed
- Verification → used to check that data does not change as it is being entered
Test data
Normal data Test data used that program would normally be expected to work with
Test data chosen to be rejected by solutions as not suitable (if program is working
Abnormal data
properly)
Extreme data Largest and smallest values that normal data can take
8 Programming
8.1 Programming concepts
Assignment statement
- Value assigned to an item/variable using “←” operator
Basic data types
- Integer → whole number (Eg. 5, -3)
- Real → number capable of containing a fractional part like float (Eg. 4.7, -4.0, 0.3)
- Char → single character (Eg. ‘x’, ‘@’)
- String → sequence of zero or more characters (Eg. “This is a string”, “”)
- Boolean → logical values true and false (TRUE, FALSE)
Input and output statements:
- Input → Eg) INPUT Name
- Output → Eg) OUTPUT “Your name is ”, Name
Sequence
- Statements executed one by one in order they are written
Selection
Boolean example:
IF Found
THEN
OUTPUT “Your search was successful”
ELSE CASE OF Grade
OUTPUT “Your search was unsuccessful” “A” : OUTPUT “Excellent”
ENDIF
“B” : OUTPUT “Good”
“C” : OUTPUT “Average”
Comparison example:
IF Age < 18 OTHERWISE OUTPUT “Improvement is needed”
THEN ENDCASE
OUTPUT “Child”
ELSE
OUTPUT “Adult”
ENDIF
Iteration
8.2 Arrays
- Fixed-length structures of elements of identical data type (first index can be zero or one)
- Declare one-dimensional array
- DECLARE <identifier> : ARRAY[<l>:<u>] OF <data type>
- Eg) DECLARE StudentNames : ARRAY[1:30] OF STRING
- Declare two-dimensional array
- DECLARE <identifier> : ARRAY[<l1>:<u1>, <l2>:<u2>] OF <data type>
- DECLARE NoughtsAndCrosses : ARRAY[1:3, 1:3] OF CHAR
- Examples of using one-dimensional array
- StudentNames[1] ← "Ali"
- NoughtsAndCrosses[2,3] ← ꞌXꞌ
- StudentNames[n+1] ← StudentNames[n]
- Example of assigning group of array elements
- FOR Index ← 1 TO 30
StudentNames[Index] ← ""
NEXT Index
9 Databases
- Database → structured collection of data that allows people to extract information in a way that meets
their needs
- Useful because : changes need to be made only once, same data used by everyone, no data duplication
- Uses : patients in hospital, books in library, hotel bookings
Primary keys
- Primary key → field that uniquely identifies the item
- Purpose → to reliably identify an item from the data stored
- Why existing fields cannot be used as primary key → could contain repeated data
Structured Query Language (SQL)
- SQL → writing scripts to obtain useful information from a database
- SQL script → list of SQL commands that perform a given task
- SQL command
- Starts with…
SELECT __(field name)__
FROM __(table name)__
(Other commands optional)
Ends with ; to show end of command
- SELECT → fetches specified fields from a table
- SELECT Field1, Field2, Field3 → specifies fields to be shown
- SELECT * → specifies that all fields are to be shown
- FROM → identifies table to use
- WHERE → includes only records that matches given condition
- WHERE Condition → specifies condition to apply
- Conditions include…
- Values from fields (matches with data type of field)
- Operators (=, >, >=,< >, BETWEEN, LIKE, IN, AND, OR, NOT)
- ORDER BY → sorts results either alphabetically or numerically
- ORDER BY Field1, Field2 → sort in ascending / alphabetical order from first field
- ORDER by Field1, Field2 DESC → sort in descending / reverse alphabetical order
- SUM
- SELECT SUM (Field) → sum of all values in a field (field should be integer or real)
- COUNT
- SELECT COUNT (Field) → Counts number of records in a field
10 Boolean logic
- Building block of digital circuit
- Perform logical operation on one or more binary inputs to produce binary output
- Electrical signal entering logic gate → 1 / No electrical signal → 0
- NOT = single input gate / All other gates = limited to two inputs
1 0
Input Output
1 0 0
1 1 1
Input Output
1 0 1
1 1 1
0 0 1
0 1 1
1 0 1
1 1 0
Input Output
1 0 0
1 1 0
Input Output
Exclusive OR A B X
X = A XOR B
0 0 0
XOR
0 1 1
1 0 1
1 1 0
A B C X
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 0
= (NOT A AND NOT B AND NOT C) OR (A AND NOT B AND NOT C) OR (A AND B AND NOT C)