AxoPrep

Computer Science

A1.2 Data representation and computer logic

How numbers, text, images and sound become binary, how to convert between bases, and how logic gates and Boolean algebra describe circuits. Study guide, 10 practice questions with markschemes and 16 flashcards. Free.

binary and hexadecimal · encoding integers, text, images and sound · logic gates and truth tables · building logic diagrams · (HL) simplifying Boolean expressions

Practise all 10 questions Study 16 flashcards

Study guide

Number bases

Computers store everything as bits. Each binary place value doubles: 128, 64, 32, 16, 8, 4, 2, 1 for one byte.

Binary to denary: add the place values that hold a 1. 11010011 = 128 + 64 + 16 + 2 + 1 = 211.

Denary to binary: subtract the largest place values that fit. 100 = 64 + 32 + 4, so 100 = 01100100.

Hexadecimal (base 16) uses 0 to 9 then A=10 to F=15. One hex digit is exactly 4 bits, so split a byte into two nibbles: 1101 0011 = D3. To go from hex to denary, multiply the first digit by 16: D3 = 13 x 16 + 3 = 211. Programmers use hex because it is short, easy to convert to binary and less error-prone to read (colours #RRGGBB, memory addresses, MAC addresses).

Negative numbers: two's complement

The leftmost bit has a negative place value (-128 in 8 bits). To encode -38: write +38 = 00100110, flip every bit to 11011001, add 1 to get 11011010. Check: -128 + 64 + 16 + 8 + 2 = -38.

8-bit range: -128 to +127. If two positives add to something above 127, the sign bit flips and the result looks negative: 01100100 (100) + 01000000 (64) = 10100100, which reads as -92. This is overflow.

Fractions are stored in floating point, which cannot represent most decimals exactly; compare floats with a tolerance, e.g. abs(a - b) < 1e-9, not with ==.

Text, images and sound

Logic gates

ABANDORNANDNORXOR
0000110
0101101
1001101
1111000

NOT simply inverts its single input.

Building logic diagrams from a scenario

A pump P runs when the tank is low (L) and the valve is open (V), unless an emergency stop (E) is pressed: \(P = (L \cdot V) \cdot \overline{E}\). Draw one gate per operator, working from the inputs towards the output, and check with a truth table. With 3 inputs a table has \(2^3 = 8\) rows; list them in binary counting order 000 to 111 so none is missed.

LVEL AND VNOT EP
000010
001000
010010
011000
100010
101000
110111
111100

Simplifying Boolean expressions (HL)

Useful laws: \(A + A \cdot B = A\) (absorption), \(A + \overline{A} = 1\), \(A \cdot \overline{A} = 0\), \(A \cdot 1 = A\), distribution \(A \cdot B + A \cdot C = A \cdot (B + C)\), and De Morgan: \(\overline{A \cdot B} = \overline{A} + \overline{B}\), \(\overline{A + B} = \overline{A} \cdot \overline{B}\).

Worked example: \(X \cdot Y + X \cdot \overline{Y} + \overline{X} \cdot \overline{Y}\)

  1. Factor the first two terms: \(X \cdot (Y + \overline{Y}) = X\)
  2. Now \(X + \overline{X} \cdot \overline{Y}\), which simplifies (redundancy law) to \(X + \overline{Y}\)

Verify with a truth table: the only row giving 0 is X = 0, Y = 1 in both forms. NAND and NOR are universal: tying both inputs of a NAND together gives NOT, so any circuit can be built from NAND alone.

Common mistakes

Exam tips

Cheat sheet

DenaryBinaryHex
101010A
111011B
121100C
131101D
141110E
151111F
25511111111FF

Key definitions

Bit

A single binary digit, 0 or 1; the smallest unit of data.

Hexadecimal

Base-16 number system using digits 0-9 and A-F; each digit represents four bits.

Two's complement

Signed-integer representation in which the most significant bit has a negative place value.

Overflow

An error that occurs when a calculation produces a value too large for the number of bits available.

Character set

An agreed mapping between characters and binary codes, such as ASCII or Unicode.

Colour depth

The number of bits used to store the colour of each pixel.

Sample rate

The number of times per second an analogue sound wave is measured when it is digitised.

Logic gate

An electronic component that produces a single binary output from one or more binary inputs according to a fixed rule.

Truth table

A table listing the output of a logic circuit for every possible combination of inputs.

De Morgan's laws (HL)

Rules that turn the negation of an AND into an OR of negations, and the negation of an OR into an AND of negations.

Practice questions

SLPaper 1Foundation

Question 1

(a) [2]

Convert the 8-bit binary number 10110110 to denary.

Markscheme
  • 1 Uses place values 128 + 32 + 16 + 4 + 2
  • 1 182
(b) [2]

Convert 10110110 to hexadecimal.

Markscheme
  • 1 Splits into nibbles 1011 and 0110
  • 1 B6
(c) [1]

Convert the denary number 75 to 8-bit binary.

Markscheme
  • 1 01001011
SLPaper 1Standard

Question 2

(a) [3]

A web designer uses the colour #3FA0C8, written as three hexadecimal bytes for red, green and blue. Calculate the denary value of each of the three components.

Markscheme
  • 1 Red 3F = 63
  • 1 Green A0 = 160
  • 1 Blue C8 = 200
(b) [2]

Explain why programmers often write values such as colours and memory addresses in hexadecimal rather than binary.

Markscheme
  • 1 Hex is shorter / more compact: one hex digit represents exactly four bits
  • 1 So it is easier for humans to read, write and remember, with fewer errors, while converting easily to binary
SLPaper 1Challenging

Question 3

(a) [3]

Represent −45 as an 8-bit two's complement binary number. Show your working.

Markscheme
  • 1 +45 written as 00101101
  • 1 Bits inverted to 11010010 and 1 added
  • 1 11010011
(b) [1]

State the range of integers that can be stored in 8-bit two's complement.

Markscheme
  • 1 −128 to +127
(c) [3]

A program adds 01110000 and 00011000 using 8-bit two's complement. Determine the 8-bit result and explain why it is incorrect.

Markscheme
  • 1 Result is 10001000
  • 1 Which is interpreted as −120 (instead of +136)
  • 1 Overflow: the true answer 136 is larger than 127, the maximum positive value, so the sign bit is changed

Key facts

How many values can n bits represent?

2ⁿ different values, e.g. 8 bits give 256 (0 to 255 unsigned).

Why use hexadecimal?

One hex digit = exactly 4 bits, so long binary values become short and easier for humans to read; the computer still stores binary.

Quick method: binary to hex

Split into groups of 4 bits from the right and convert each group, e.g. 1011 0110 = B6.

How do you negate a number in two's complement?

Invert every bit, then add 1. Example: 45 = 00101101 → 11010011 = −45.

Range of 8-bit two's complement

−128 to +127. The most significant bit has place value −128.

What is overflow?

When a result is too large for the number of bits available, e.g. 112 + 24 in 8-bit two's complement gives −120.