// Computer Science Notes

Detailed notes & self-check questions

Clear topic notes with diagrams, plus model questions โ€” hit "Show worked answer" to check yourself. Suitable for O Level, IGCSE, A Level, AP and IB foundations.

๐Ÿ“š This notes library is growing. The topics below are complete examples with the same format every topic will follow โ€” notes, a diagram, then model questions with worked answers. More topics (networks, databases, OOP, security, OS, and full board-by-board coverage) are being added.
DATA REPRESENTATION

1 ยท Number Systems: Binary, Denary & Hexadecimal

Computers store everything as binary (base 2) โ€” only 0s and 1s โ€” because a circuit is either off (0) or on (1). Humans use denary (base 10). Hexadecimal (base 16) is a shorthand for binary that is easier to read.

Place values (8-bit binary)

Each bit has a value that doubles from right to left. To find the denary value, add the place values wherever there is a 1.

1286432168421 0 1 0 0 1 1 0 1 64 + 8 + 4 + 1 = 77 (denary) = 4D (hex)
Worked example: binary 01001101 โ†’ 77 in denary โ†’ 4D in hexadecimal

Denary โ†’ Binary

Keep subtracting the largest place value that fits, writing a 1 each time, 0 otherwise.
Example: 77 โ†’ 64 fits (1), 32 no (0), 16 no (0), 8 fits (1), 4 fits (1), 2 no (0), 1 fits (1) โ†’ 01001101.

Binary โ†’ Hex (the easy way)

Split the 8 bits into two groups of four. Each group of four bits = one hex digit (0โ€“F). 0100 = 4, 1101 = D, so the byte is 4D.

Q1Convert the denary number 156 into 8-bit binary.
Worked answer128 fits (1), remainder 28. 64 no (0), 32 no (0), 16 fits (1) rem 12, 8 fits (1) rem 4, 4 fits (1) rem 0, 2 no (0), 1 no (0). Reading the bits: 10011100. Check: 128+16+8+4 = 156. โœ“
Q2Convert binary 11100110 to hexadecimal.
Worked answerSplit into nibbles: 1110 and 0110. 1110 = 8+4+2 = 14 = E. 0110 = 4+2 = 6. Answer: E6.
Q3State one reason programmers use hexadecimal instead of binary.
Worked answerHex is much shorter and easier for humans to read and write than long strings of binary, so there are fewer mistakes (one hex digit represents four bits). Also accepted: easier to debug / takes less screen space.
LOGIC & BOOLEAN

2 ยท Logic Gates & Truth Tables

Logic gates are the building blocks of a processor. Each takes one or more binary inputs and gives a single binary output, following a fixed rule shown in a truth table.

ANDORNOT
The three core gates. AND/OR take two inputs; NOT takes one and inverts it.

Truth tables

ABA AND BA OR BNOT A
00001
01011
10010
11110

Remember: AND = output 1 only if both inputs are 1. OR = output 1 if either input is 1. NOT = flips the input.

Q1Complete the output of NOT (A AND B) (this is a NAND gate) when A = 1, B = 0.
Worked answerA AND B = 1 AND 0 = 0. NOT 0 = 1. So the NAND output is 1.
Q2An alarm rings when a door is open AND the system is armed. Door = D, Armed = S. Write the logic expression.
Worked answerAlarm = D AND S. The alarm output is 1 only when both D = 1 and S = 1.
ALGORITHMS

3 ยท Searching & Sorting

Linear search

Check each item one at a time from the start until the target is found or the list ends. Simple, works on any list, but slow for large lists.

FOR i <- 0 TO LENGTH(list) - 1
  IF list[i] = target THEN
    RETURN i        // found at position i
  ENDIF
NEXT i
RETURN -1           // not found

Bubble sort

Repeatedly step through the list, comparing each pair of neighbours and swapping them if they are in the wrong order. After each full pass the largest remaining value "bubbles" to the end.

FOR pass <- 1 TO LENGTH(list) - 1
  FOR i <- 0 TO LENGTH(list) - 2
    IF list[i] > list[i+1] THEN
      // swap them
      temp <- list[i]
      list[i] <- list[i+1]
      list[i+1] <- temp
    ENDIF
  NEXT i
NEXT pass

Try these in the Pseudocode IDE to watch them run.

Q1Using a linear search, how many comparisons to find 9 in [4, 7, 2, 9, 5]?
Worked answerCompare 4 (no), 7 (no), 2 (no), 9 (yes). That is 4 comparisons, found at position index 3.
Q2Show the list [5, 3, 8, 1] after one full pass of bubble sort.
Worked answerCompare 5 & 3 โ†’ swap โ†’ [3,5,8,1]. Compare 5 & 8 โ†’ no swap. Compare 8 & 1 โ†’ swap โ†’ [3,5,1,8]. After one pass: [3, 5, 1, 8] (8 has bubbled to the end).
Want a specific topic added next? Tell Sir Sikandar โ†’