← Back to subjects
⭐ 0
OCR A-level Computer Science (H446) Β· Data types, data structures & algorithms
Mini-Lesson

Data types, structures & Boolean algebra

This mini-lesson covers OCR 1.4 β€” Data types, data structures and algorithms, including the Boolean algebra in 1.4.3 that so many candidates skip and then lose marks on.

  • Primitive types, two's complement and binary arithmetic
  • Hexadecimal, floating point and normalisation
  • Bitwise masks and shifts; overflow
  • Data structures β€” arrays, linked lists, stacks, queues, trees, graphs, hash tables
  • Boolean algebra, De Morgan's laws, Karnaugh maps, adders and flip-flops

Work through each screen, answer the questions as you go (some are recall, some are calculations you must actually work out) and collect ⭐ stars. Press Start when you're ready.

1.4 Β· Types

Primitive data types

TypeHoldsTypical size
integerwhole numbers2 or 4 bytes
real / floatnumbers with a fractional part4 or 8 bytes
charactera single symbol1 byte (ASCII)
stringa sequence of charactersvaries
BooleanTrue or False1 bit, usually padded to 1 byte

ASCII uses 7 bits for 128 characters β€” English only. Unicode assigns a code point to every character in every script, needing 16 bits or more.

Choose the smallest type that works. Integers are exact; reals are floating point and carry rounding error. Store money as an integer number of pence, never as a real β€” a fraction of a penny that cannot be represented exactly will, given enough transactions, cost someone real money.

1.4 Β· Binary

Two's complement and binary arithmetic

In two's complement the most significant bit carries a negative weight:

-128 64 32 16 8 4 2 1 1 1 1 0 1 1 0 0 = -128 + 64 + 32 + 8 + 4 = -20

To negate: write the positive value, flip every bit, then add 1. So +20 = 00010100 β†’ flip = 11101011 β†’ +1 = 11101100 = βˆ’20.

Range in 8 bits: βˆ’128 to +127.

Subtraction becomes addition: A βˆ’ B is computed as A + (βˆ’B), so one adder circuit does both jobs. Sign and magnitude is the alternative β€” the MSB is simply a sign flag β€” but it has two representations of zero and needs separate subtraction hardware, which is why nobody uses it.

Binary addition

  01101101  (109)

+ 00101110  (46)

= 10011011  (155) β€” carry each 1+1 into the next column

Overflow: the result of that sum, 155, is fine as an unsigned byte β€” but read as two's complement the same bits mean βˆ’101. When a result will not fit the word length, the sign flips and the answer is silently wrong. That is overflow, and it is why the status register has an overflow flag.

Calculate

Your turn β€” binary addition

1Add these two 8-bit binary numbers and give the 8-bit result:
01101101 + 00101110
Hint: Work right to left, carrying into the next column whenever a column totals 2. (Check yourself in denary: 109 + 46.)
1.4 Β· Hex & floats

Hexadecimal, floating point and normalisation

Hexadecimal is base 16: digits 0–9, then A=10, B=11, C=12, D=13, E=14, F=15. One hex digit is exactly 4 bits, so a byte is always two hex digits. It is used for memory addresses, colour codes and MAC addresses because it is compact and converts to binary with no arithmetic.

3F = (3 Γ— 16) + 15 = 48 + 15 = 63 3F = 0011 1111 in binary

Floating point stores a number as:

value = mantissa Γ— 2exponent

The mantissa holds the significant digits and so sets the precision; the exponent places the binary point and so sets the range. For a fixed word length, bits given to one are taken from the other.

Normalisation removes leading redundant bits to maximise precision: a positive normalised mantissa starts 0.1; a negative one starts 1.0. The exponent is adjusted to compensate, so the value never changes.

Worked example

Mantissa 0.0110, exponent 0011 (= 3).

0.0110 in binary = 0.25 + 0.125 = 0.375. Multiply by 2Β³ = 8 β†’ 3

Normalised, this is 0.1100 Γ— 2Β² = 0.75 Γ— 4 = 3 β€” same value, one more bit of precision.

Calculate

Your turn β€” hex to denary

2Convert the hexadecimal number 3F to denary.
Hint: The left digit is worth 16 each; F is 15.
Calculate

Your turn β€” floating point

3A number is stored with mantissa 0.0110 and exponent 0011, both in two's complement. What is its value in denary?
Hint: 0.0110 in binary is 0.25 + 0.125. The exponent 0011 is 3, so multiply by 2Β³.
1.4 Β· Bitwise

Bitwise masks and shifts

A mask uses AND, OR or XOR with a chosen pattern to isolate or change specific bits:

AND with 0 β†’ clears the bit; AND with 1 β†’ keeps it OR with 1 β†’ sets the bit XOR with 1 β†’ flips the bit 10110110 data AND 00001111 mask // keep only the low nibble = 00000110

Shifts: a logical shift left by n multiplies by 2ⁿ; a logical shift right by n divides by 2ⁿ (discarding the remainder). Bits shifted off the end are lost, and zeros are shifted in.

00001010 (10) LSL 2 β†’ 00101000 (40) // Γ— 4 00101000 (40) LSR 3 β†’ 00000101 (5) // Γ· 8

Why bother? A shift is a single, extremely fast instruction, whereas a general multiply takes several cycles. Masks are how a program packs several flags into one byte and reads them back out β€” vital in embedded systems and network protocols where every bit counts.

Calculate

Your turn β€” the mask

4Apply the mask below and give the 8-bit result:
10110110 AND 00001111
Hint: AND gives 1 only where both bits are 1. The four leading zeros in the mask clear the top four bits.
1.4 Β· Structures

Data structures

  • Array β€” fixed size, all elements the same type, O(1) access by index. Inserting in the middle means shifting everything after it.
  • Record β€” fields of different types grouped together.
  • Tuple β€” ordered and immutable; a list is ordered and mutable.
  • Linked list β€” each node holds data plus a pointer to the next. Insertion and deletion are O(1) once you are there (just re-point), but finding an element is O(n) β€” you cannot jump to the middle.
  • Stack β€” LIFO. push, pop, peek. Used for the call stack, undo, RPN and depth-first search. Beware overflow and underflow.
  • Queue β€” FIFO, with front and rear pointers. A circular queue wraps them round with MOD so no space is wasted. A priority queue serves by priority, not arrival.
  • Tree β€” connected, no cycles, one root. In a binary search tree, left < node < right, so search is O(log n) when balanced.
  • Graph β€” vertices joined by edges; may be directed and weighted. Stored as an adjacency matrix (O(nΒ²), good for dense) or an adjacency list (O(n + e), good for sparse).
  • Hash table β€” the key computes its own index via a hash function, so access is O(1) on average. Collisions are resolved by probing or chaining.

Array vs linked list β€” the real trade-off: arrays give instant access by index but expensive insertion; linked lists give cheap insertion but force you to walk from the head. Choose on the basis of which operation you will do most often.

Quick check

Choosing a structure

?A program repeatedly inserts and deletes items in the middle of a long sequence, and rarely needs random access by index. Which structure is best?
1.4.3 Β· Boolean

Boolean algebra and De Morgan's laws

GateOutput is 1 when…
NOT Δ€the input is 0
AND A Β· Bboth inputs are 1
OR A + Bat least one input is 1
XOR A βŠ• Bthe inputs differ
NAND / NORthe inverse of AND / OR

A truth table with n inputs has 2ⁿ rows. The laws you must know:

LawIdentity
CommutationA Β· B = B Β· A    A + B = B + A
Association(A Β· B) Β· C = A Β· (B Β· C)
DistributionA Β· (B + C) = AΒ·B + AΒ·C
AbsorptionA + (A Β· B) = A
Double negationNOT(NOT A) = A
De MorganNOT(A Β· B) = Δ€ + BΜ„    NOT(A + B) = Δ€ Β· BΜ„
Worked simplification

AΒ·B + AΒ·BΜ„ = A Β· (B + BΜ„) = A Β· 1 = A

Two gates become none. B was irrelevant all along.

Quick check

De Morgan

?Which expression is equivalent to NOT(A Β· B)?
1.4.3 Β· Circuits

Karnaugh maps, adders and flip-flops

A Karnaugh map simplifies a function visually. Cells are laid out in Gray code order (00, 01, 11, 10) so adjacent cells differ in exactly one variable.

  • Group the 1s in blocks of 1, 2, 4, 8 β€” powers of two only.
  • Make each group as large as possible; groups may overlap and may wrap round the edges.
  • Any variable that changes within a group is eliminated; those that stay constant form the term.
Worked example

F = 1 for the minterms 000, 001, 100, 101 (in ABC order).

In all four, B = 0, while A and C each take both values.

A and C vary, so both are eliminated: F = NOT B.

Half adder: Sum = A βŠ• B, Carry = A Β· B. It cannot accept a carry in.
Full adder: Sum = A βŠ• B βŠ• Cα΅’β‚™, and Cβ‚’α΅€β‚œ = (A Β· B) + (Cα΅’β‚™ Β· (A βŠ• B)). Chain n of them and you have an n-bit adder.

D-type flip-flop: on the rising edge of the clock, whatever is on D is captured on Q and held. That is one bit of memory β€” the building block of every register and of SRAM cache.

Quick check

Karnaugh maps

?Why must the cells of a Karnaugh map be arranged in Gray code order (00, 01, 11, 10) rather than ordinary binary order?
Sort it

Sort the terms

Tap a term, then tap the group it belongs to.

πŸ”€ Primitive data type

🧱 Data structure

πŸ”Œ Logic gate

Match it

Match the description to the term

Tap an item on the left, then its partner on the right.

Description
Term
Recap

The big ideas to know

Types: integer Β· real Β· character Β· string Β· Boolean Β· ASCII (7-bit) vs Unicode Β· store money in pence

Two's complement: MSB is negative Β· negate = flip and add 1 Β· 8-bit range βˆ’128 to +127 Β· subtraction becomes addition Β· overflow flips the sign

Hex & floats: one hex digit = 4 bits Β· 3F = 63 Β· mantissa Γ— 2^exponent Β· normalise: positive starts 0.1, negative 1.0

Bitwise: AND masks bits out, OR sets, XOR flips Β· LSL n = Γ— 2ⁿ, LSR n = Γ· 2ⁿ

Structures: array O(1) access Β· linked list O(1) insert Β· stack LIFO Β· queue FIFO Β· BST O(log n) Β· hash table O(1) average

Boolean: 2ⁿ truth-table rows Β· AΒ·B + AΒ·BΜ„ = A Β· De Morgan Β· Karnaugh maps need Gray code Β· half/full adder Β· D-type flip-flop

That is the whole of OCR 1.4 β€” including the Boolean algebra of 1.4.3. Press Finish to see your score.

πŸ†

Mini-lesson complete!

⭐⭐⭐

You've worked through Data types, structures & Boolean algebra for OCR A-level Computer Science (H446). πŸŽ‰

Your stars: 0 / 0

Next: test yourself in the Evaluate stage Confidence Quiz, then lock it in with Verify.

πŸ“£ Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

β†’ Back to all subjects