DR

1.1 Data Representation

Understanding why computers use binary, the denary, binary and hexadecimal number systems, conversions, binary addition, logical shifts and two's complement.

Learning Objectives

By the end of this lesson, you will be able to:

  • Understandhow and why computers use binaryto represent all forms of data
  • Understand thedenary(base 10),binary(base 2) andhexadecimal(base 16) number systems
  • Convert betweenpositive denary and positive binary
  • Convert betweenpositive denary and positive hexadecimal
  • Convert betweenpositive hexadecimal and positive binary
  • Understand how and whyhexadecimalis used as a beneficial method of data representation, includingMAC addresses,colour codes,URLsanderror codes
  • Add twopositive 8-bit binary integers
  • Understand the concept ofoverflowand why it occurs in binary addition
  • Performlogical binary shiftson a positive 8-bit binary integer and understand the effect this has on the value
  • Usetwo's complementto represent positive and negative 8-bit binary integers
  • Understand themeasurement of computer memory sizes(bit, nibble, byte, KB/KiB, MB/MiB, GB/GiB, TB/TiB, PB/PiB)

Key Terms

Bit

A single binary digit — either 0 or 1. The smallest unit of data.

Nibble

A group of 4 bits (half a byte). One nibble = one hexadecimal digit.

Byte

A group of 8 bits. The standard unit for storing a single character.

Denary (Decimal)

The everyday base-10 number system using digits 0–9.

Binary

The base-2 number system using only 0 and 1.

Hexadecimal

The base-16 number system using 0–9 and A–F. One hex digit represents 4 bits.

Most Significant Bit (MSB)

The left-most bit in a binary number — it has the largest place value.

Least Significant Bit (LSB)

The right-most bit in a binary number — it has the smallest place value (1).

Overflow

An error that occurs when the result of a calculation needs more bits than the register can hold.

Logical Shift

Moving bits left or right. Left shift multiplies by 2; right shift divides by 2.

Two's Complement

A method of representing negative numbers in binary. The MSB carries a negative weight.

Sign Bit

The MSB in a signed binary number: 0 = positive, 1 = negative.

MAC Address

A 48-bit unique hardware address written as 6 pairs of hexadecimal digits.

HTML Colour Code

A 6-digit hexadecimal code (#RRGGBB) representing red, green and blue intensities.

Kibibyte (KiB)

1024 bytes (2¹⁰ bytes). Used for measuring internal memory like RAM.

Kilobyte (KB)

1000 bytes (10³ bytes) in decimal. Commonly used for storage sizes.

Memory Dump

A printout of memory contents, usually shown in hexadecimal to help trace errors.

Register

A small, fast storage area inside the CPU that holds binary values being processed.

URL Encoding

Special characters in a URL are converted into hexadecimal codes prefixed with %.

1. Why Computers Use Binary

Any form of data needs to be converted tobinaryto be processed by a computer. Data is processed usinglogic gatesand stored inregisters.

Key Ideas

  • Computers are made up of millions of tinyswitches(transistors).
  • A switch that isONis represented by1.
  • A switch that isOFFis represented by0.
  • Switches uselogic gatesthat can only havetwo states(1 or 0).
  • Because there are only two possible states, all data must be converted tobinarybefore a computer can understand and process it.
  • Converting data to binary allows computers to process it at incredible speed, perform complex calculations and store vast amounts of data efficiently.

Secondary Storage Examples

  • Magnetic hard drivesuseNorth and South polarityto represent a 1 or a 0.
  • Inoptical disks, light hitting a flat area (land) is interpreted as a1and light hitting a bump (pit) is interpreted as a0.

Optical disk encoding

Land = 1     Pit = 0
1 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0

Real-Life Analogy: Driving a Car

When driving a car, the accelerator pedal is used to increase the car's speed. If a car was accelerating from 50 mph to 100 mph, the increase would be gradual.

In a computer system, the car is doing either 50 mph (0) or 100 mph (1) — there is no in-between. Trying to change the computer system so that it has more options would beless efficientand requiremore complex parts.

Worked Example

Question:Explain why computers process data in binary format. [2]

Answer:

  • Computers process data using logic gates... [1]
  • ... that can only have two states (1/0) [1]

Exam tip: Mark schemes expect "logic gates + two states (1/0)". Phrases like "computers understand binary" do not get the mark.

Activity 1: Binary in Everyday Devices

A student says: "Computers use binary because it is easier for humans to read." Explain why this statement is incorrect. In your answer, refer to logic gates, switches and the two states of a computer. [4 marks]

Solution:
  • [1] Computers do not use binary because it is easier for humans — binary is actually harder for humans to read than denary.
  • [1] Computers use binary because they are made of millions of switches (transistors) that can only be ON (1) or OFF (0).
  • [1] Data is processed using logic gates that only have two possible states (1 or 0).
  • [1] Therefore all data must be converted to binary before a computer can process it.

Check Your Understanding: Why Binary?

  • [1]ON — represented by the binary digit 1
  • [1]OFF — represented by the binary digit 0
  • Additional:These two states are the basis of all data storage and processing in a computer.
  • [1]Magnetic hard drives use North and South polarity to represent binary values
  • [1]One polarity represents a 1 and the other represents a 0
  • [1]Light hitting a flat area (land) is interpreted as a 1
  • [1]Light hitting a bump (pit) is interpreted as a 0
  • [1]Computers are made from logic gates that only have two states (1 or 0)
  • [1]Denary has ten digits (0–9), which cannot be represented directly by a two-state switch, so data must be converted to binary first
  • [1]Having only two states is simpler and more reliable — it is easy to tell if a switch is ON or OFF
  • [1]Using more states would require more complex components and would be less efficient, and small voltage changes could cause errors
  • [1]All data (text, images, sound, video) is stored as binary (1s and 0s)
  • [1]Different types of data use different encoding methods (e.g. ASCII for text, pixels for images)
  • [1]The computer does not know what the data "means" — it just processes the binary patterns

2. The Denary, Binary & Hexadecimal Number Systems

Anumber systemis a way of representing amounts or quantities of something. Different number systems use differentbases. The base tells you how many different digits are used in that system.

Denary

  • Base 10
  • Digits: 0–9
  • Used by humans in everyday life
  • Each column is a power of 10
10³ 10² 10¹ 10⁰
1000 100 10 1

Binary

  • Base 2
  • Digits: 0 and 1
  • Used by computers
  • Each column is a power of 2
2³ 2² 2¹ 2⁰
8 4 2 1

Hexadecimal

  • Base 16
  • Digits: 0–9 and A–F
  • Used by humans as shorthand for binary
  • Each column is a power of 16
16¹ 16⁰
16 1

Hexadecimal Reference Table

Denary0123456789101112131415
Binary0000000100100011010001010110011110001001101010111100110111101111
Hex0123456789ABCDEF

Exam Tips & Tricks

  • All conversions at IGCSE are capped at16 bits.
  • The largest denary number that can be represented using 16 bits is65,535(binary 1111111111111111).
  • One hexadecimal digit represents exactly four bits (one nibble).
  • Write out the hex digits (0–F) during the exam to avoid confusion.

Activity 2: Recognising Number Systems

Look at the following values. State whether each onemustbe binary, hexadecimal, or could be either. Explain each answer.

  1. 1010
  2. 2F
  3. 1001
  4. 7C
  5. 0
Solution:
  1. 1010— Could be either. All digits are 0s and 1s, so it is a valid binary number. It is also a valid hexadecimal number (using only digits 0 and 1).
  2. 2F— Must be hexadecimal. The letter F cannot appear in a binary number.
  3. 1001— Could be either. Valid binary (only 0s and 1s) and also valid hex.
  4. 7C— Must be hexadecimal. The letter C cannot appear in binary.
  5. 0— Could be either. It is valid in every number system.

Check Your Understanding: Number Systems

  • [1]Base 10 — it uses ten digits (0–9)
  • [1]Hexadecimal uses 16 different digits: 0–9 and A–F
  • [1]Each digit position represents a power of 16
  • [1]4 bits (half a byte). One nibble corresponds to exactly one hexadecimal digit.
  • [1]255 (binary 11111111). If you try to represent 256, an overflow error occurs.
  • [1]Any correct pair, for example: denary 15 = hex F
  • [1]Another correct pair, for example: denary 28 = hex 1C or denary 255 = hex FF
  • [1]Humans use denary (base 10)
  • [1]Computers use binary (base 2). Hexadecimal is used by humans as a shorthand for binary, but computers translate hex back to binary before processing.

3. Measurement of the Size of Computer Memories

Bit

Each individual 1 or 0 is known as a bit.

Example:0is one bit.

Nibble

A nibble is 4 bits, or half a Byte.

Example:1101is one nibble.

Byte

Each group of 8 bits is known as a Byte.

Example:11001100is one byte.

Decimal (SI) Units

Name of memory sizeEquivalent denary value (bytes)
1 kilobyte (1 KB)1 000
1 megabyte (1 MB)1 000 000
1 gigabyte (1 GB)1 000 000 000
1 terabyte (1 TB)1 000 000 000 000
1 petabyte (1 PB)1 000 000 000 000 000
1 exabyte (1 EB)1 000 000 000 000 000 000
1 zettabyte (1 ZB)1 000 000 000 000 000 000 000
1 yottabyte (1 YB)1 000 000 000 000 000 000 000 000

Binary (IEC) Units

Name of memory sizeNumber of bytesEquivalent denary value (bytes)
1 kibibyte (1 KiB)2¹⁰1 024
1 mebibyte (1 MiB)2²⁰1 048 576
1 gibibyte (1 GiB)2³⁰1 073 741 824
1 tebibyte (1 TiB)2⁴⁰1 099 511 627 776
1 pebibyte (1 PiB)2⁵⁰1 125 899 906 842 624
1 exbibyte (1 EiB)2⁶⁰1 152 921 504 606 846 976
1 zebibyte (1 ZiB)2⁷⁰1 180 591 620 717 411 303 424
1 yobibyte (1 YiB)2⁸⁰1 208 925 819 614 629 174 706 176

The Difference Between Kilobytes and Kibibytes

  • Akibibyte (KiB)is the formal name for1024 bytes(2¹⁰).
  • Akilobyte (KB)is1000 bytes(10³) according to SI naming conventions.
  • In practice, powers of 1024 bytes tend to be used forRAM(internal memory).
  • Powers of 1000 tend to be used forselling hard disks and other persistent storage.
  • Internal memories (such as RAM) should be measured using the IEC system.A 64 GiB RAM could therefore store 64 × 2³⁰ bytes of data (68 719 476 736 bytes).

Quick Conversion Tip

To convert between IEC units, multiply or divide by 1024 each time. For example, to go from KiB to MiB, divide by 1024. To go from GiB to MiB, multiply by 1024.

Activity 3: Memory Size Calculations

Answer the following questions. Show all working.

  1. How many bytes are in 3 KiB?
  2. A hard drive is advertised as 2 TB. How many bytes is this using decimal (SI) units?
  3. A computer has 16 GiB of RAM. How many bytes is this using IEC units?
  4. Explain why a 1 TB hard drive shows less than 1 TB in Windows File Explorer (which uses IEC units).
Solution:
  1. 3 × 1024 =3 072 bytes
  2. 2 × 1 000 000 000 000 =2 000 000 000 000 bytes
  3. 16 × 2³⁰ = 16 × 1 073 741 824 =17 179 869 184 bytes
  4. The manufacturer uses decimal (1 TB = 1 000 000 000 000 bytes), but the operating system uses binary (1 TiB = 1 099 511 627 776 bytes). 1 000 000 000 000 ÷ 1 099 511 627 776 ≈ 0.909 TiB, so it appears as about 909 GiB.

Check Your Understanding: Memory Measurement

  • [1]8 bits = 1 byte
  • [1]1 024 bytes (2¹⁰)
  • [1]Internal memory is built using powers of 2 (e.g. 8, 16, 32, 64 GiB), so IEC units match the physical structure
  • [1]The IEC system is more accurate for measuring internal memory because 1 KiB = 1024 bytes exactly
  • [1]24 bits (3 × 8)
  • [1]1 KB = 1 000 bytes (decimal/SI units)
  • [1]1 KiB = 1 024 bytes (binary/IEC units)
  • [1]64 × 2³⁰
  • [1]= 68 719 476 736 bytes

4. Converting Between Number Systems

Interactive Number System Converter

Type a value into any box and the other boxes will update automatically. Try converting denary 45, hex B5 or binary 10110101.

Tip:If a value contains only 0s and 1s it could be binary or hex. If it contains A–F it must be hex.

A) Converting from Denary to Binary

Method: Place Value Table

Write out the binary column headings. Find the first heading larger than your denary number. Use the headings to the right of it.

Example: Convert 45 to binary
The first heading bigger than 45 is 64, so use: 32 16 8 4 2 1
32 fits into 45 once (remainder 13) → 1
16 fits into 13 zero times → 0
8 fits into 13 once (remainder 5) → 1
4 fits into 5 once (remainder 1) → 1
2 fits into 1 zero times → 0
1 fits into 1 once → 1
Denary 45 = 101101 in binary

Method: Repeated Division by 2

Repeatedly divide the denary number by 2, writing down the remainder each time. Read the remainders from bottom to top.

Example: Convert 203 to binary
203 ÷ 2 = 101 remainder 1
101 ÷ 2 = 50 remainder 1
50 ÷ 2 = 25 remainder 0
25 ÷ 2 = 12 remainder 1
12 ÷ 2 = 6 remainder 0
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
Reading bottom to top: 11001011

B) Converting from Binary to Denary

Method

Write out the column headings for the number of bits given (from right to left). Add together any column heading that has a 1 under it.

Example 1: Convert 1011 to denary
8 4 2 1
1 0 1 1
1×8 + 0×4 + 1×2 + 1×1 = 11
Binary 1011 = 11 in denary
Example 2: Convert 01100011 to denary
128 64 32 16 8 4 2 1
0 1 1 0 0 0 1 1
1×64 + 1×32 + 1×2 + 1×1 = 99
Binary 01100011 = 99 in denary
Example 3: Convert 01110001110100 to denary
8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
0 1 1 1 0 0 0 1 1 1 0 1 0 0
4096 + 2048 + 1024 + 64 + 32 + 16 + 4 = 7284
Binary 01110001110100 = 7284 in denary

C) Converting from Denary to Hexadecimal

Method 1: Denary → Binary → Hex

Example: Convert 28 to hex
28 in binary = 00011100
Split into nibbles: 0001 | 1100
0001 = 1, 1100 = 12 = C
Denary 28 = 1C in hex

Method 2: Divide by 16

Example: Convert 2004 to hex
2004 ÷ 16 = 125 remainder 4
125 ÷ 16 = 7 remainder 13 (D)
7 ÷ 16 = 0 remainder 7
Read remainders bottom to top: 7 D 4
Denary 2004 = 7D4 in hex

D) Converting from Hexadecimal to Denary

Method 1: Hex → Binary → Denary

Example: Convert B9 to denary
B = 11 = 1011, 9 = 1001
Join: 10111001
1×128 + 1×32 + 1×16 + 1×8 + 1×1 = 185
Hex B9 = 185 in denary

Method 2: Multiply by 16

Example: Convert 79 to denary
7 × 16 = 112
112 + 9 = 121
Hex 79 = 121 in denary
Example: Convert 45A to denary
4 × 256 = 1024
5 × 16 = 80
A (10) × 1 = 10
Hex 45A = 1114 in denary

E) Converting from Binary to Hexadecimal

Split the binary number into groups of 4 bits (nibbles) starting from the right. If the last group has fewer than 4 bits, fill in with 0s from the left. Convert each nibble to its hexadecimal digit.

Example 1: Convert 10110111 to hex
Split: 1011 | 0111
1011 = 11 = B, 0111 = 7
Binary 10110111 = B7 in hex
Example 2: Convert 00111001 to hex
Split: 0011 | 1001
0011 = 3, 1001 = 9
Binary 00111001 = 39 in hex

F) Converting from Hexadecimal to Binary

Take each hexadecimal digit and write down the 4-bit binary code that corresponds to it. Put the groups together.

Example: Convert 5F to binary
5 = 0101, F (15) = 1111
Join: 01011111
Hex 5F = 01011111 in binary
Example: Convert 26 to binary
2 = 0010, 6 = 0110
Join: 00100110
Hex 26 = 00100110 in binary

Activity 4: Conversions Practice

Convert the following. Show your working.

  1. Denary 165 → binary
  2. Binary 01111001 → denary
  3. Denary 227 → hexadecimal
  4. Hex 4A → denary
  5. Binary 11000011 → hex
  6. Hex 9C → binary
  7. IP address values: Convert denary 167 and 214 to 8-bit binary.
Solution:
  1. 165 = 128 + 32 + 4 + 1 =10100101
  2. 01111001 = 64 + 32 + 16 + 8 + 1 =121
  3. 227 ÷ 16 = 14 (E) remainder 3 →E3
  4. 4 × 16 = 64; 64 + 10 =74
  5. Split: 1100 | 0011 → C3 =C3
  6. 9 = 1001, C (12) = 1100 →10011100
  7. 167 = 10100111, 214 = 11010110

Check Your Understanding: Conversions

  • [1]01110011 (64 + 32 + 16 + 2 + 1 = 115)
  • [1]128 + 64 + 8 + 2 = 202
  • [1]490 ÷ 16 = 30 remainder 10 (A)
  • [1]30 ÷ 16 = 1 remainder 14 (E); 1 ÷ 16 = 0 remainder 1 →1EA
  • [1](16 × 15) + (1 × 15) = 240 + 15 = 255
  • [1]Split: 1111 | 0111
  • [1]1111 = F, 0111 = 7 →F7
  • [1]A = 1010, 9 = 1001 → binary 10101001
  • [1]10 × 16 = 160
  • [1]160 + 9 = 169 in denary

5. Uses of Hexadecimal

In Computer Science, hexadecimal is often preferred when working with large values. It takesfewer digitsto represent a given value in hexadecimal than in binary. One hexadecimal digit corresponds to4 bits(one nibble) and can represent16 unique values(0–F).

Why is hexadecimal used?

  • The more bits there are in a binary number, the harder it makes it for a human to read.
  • Numbers with more bits are more prone to errors when being copied.
  • Hexadecimal is shorter and easier to remember than binary.

Exam tip: Use phrases like "fewer digits = easier for humans to read" or "less chance of copying errors".

MAC Addresses

  • AMAC address(Media Access Control address) is a number thatuniquely identifies a deviceon a network.
  • It refers to thenetwork interface card (NIC)which is part of the device.
  • It is rarely changed so that a particular device can always be identified no matter where it is.
  • A MAC address is usually made up of48 bitswhich are shown as6 groups of two hexadecimal digits.
  • The first half (NN-NN-NN) is themanufacturer identity number.
  • The second half (DD-DD-DD) is theserial numberof the device.
Example MAC address:
00-1C-B3-4F-25-FE
Manufacturer code: 001CB3 (Apple Corporation)
Serial number: 4F25FE
Equivalent binary: 48 bits — writing this out would be very error-prone!

Colour Codes

  • Hex can be used to represent colours on web pages and image-editing programs using the format#RRGGBB(RR = reds, GG = greens, BB = blues).
  • The# symbolindicates that the number has been written in hex format.
  • This system usestwo hex digits for each colour, e.g. #FF6600.
  • The values for each colour run between00 and FF. In binary, 00 is 0000 0000 and FF is 1111 1111.
  • That provides256 possible valuesfor each of the three colours.
  • That gives a total spectrum of 256 reds × 256 greens × 256 blues — which is over16 million coloursin total.
  • #FF0000is the purest red — red only, no green or blue.
  • Blackis #000000 — no red, no green and no blue.
  • Whiteis #FFFFFF.
#FF0000
Red
#00FF00
Green
#0000FF
Blue
#FF6600
Orange

RGB model:An orange colour that is #FF6600 in hex would be 255, 102, 0 in RGB.

Error Codes & Memory Dumps

  • Error codesare often shown as hexadecimal values.
  • These numbers refer to thememory location of the errorand are usually automatically generated by the computer.
  • When memory contents are output to a printer or monitor, this is known as amemory dump.
  • A program developer can look at each hexadecimal code and determine where the error lies.
  • The value on the far left shows thememory location, so it is possible to find out exactly where in memory the fault occurs.
  • This is much more manageable using hexadecimal rather than binary — it is a very powerful fault-tracing tool.
Example memory dump (hex):
00990F60 54 68 69 73 20 69 73 20 61 6E 20 65 78 61 6D 70 6C 65 20 6F 66
00990F77 61 20 6D 65 6D 6F 72 79 20 64 75 6D 70 20 66 72 6F 6D 20 61
00990E8E 74 79 70 69 63 61 6C 20 63 6F 6D 70 75 74 65 72 20 20 6D 85
This is far easier to read than the equivalent binary!

URLs

  • A URL can only contain standard characters (a–z and A–Z), numbers (0–9) and some special symbols.
  • If a URL needs to include a character outside of this set, it is converted into ahexadecimal code.
  • Hexadecimal codes included in a URL are prefixed with a% sign.

IPv6 Addresses

  • AnIPv4 addressis a 32-bit number written in denary or hexadecimal form, e.g. 109.108.158.1 (or 77.76.9e.01 in hex).
  • AnIPv6 addressis a 128-bit number broken down into 16-bit chunks, represented by hexadecimal numbers.
  • IPv6 uses acolon (:)rather than a decimal point (.) as used in IPv4.
Example IPv6 address:
a8ff:7a88:ffc3:0ff:3d21:2c95:6c7b:d0a

Activity 5: Hexadecimal in the Real World

Answer the following questions.

  1. Describe two applications of the hexadecimal system. [4]
  2. A MAC address is 00-1C-B3-4F-25-FE. What part of this address identifies the manufacturer? [1]
  3. Explain why hexadecimal is used for MAC addresses instead of binary. [2]
  4. What colour is #000000? What about #FFFFFF? [2]
Solution:
  1. Any two of: MAC addresses, colour codes, URLs, error codes, memory dumps, IPv6 addresses. (2 marks each, 1 for naming, 1 for explaining.)
  2. 00-1C-B3— this is the manufacturer ID.
  3. MAC addresses are 48 bits long. Binary would be 48 digits (very hard to read and prone to errors). Hexadecimal uses only 12 digits, so it is shorter, easier to read and less error-prone.
  4. #000000 is black (no red, no green, no blue). #FFFFFF is white (all colours at full intensity).

Check Your Understanding: Uses of Hex

  • [1]12 hexadecimal digits (48 bits)
  • [1]Hex is shorter than binary (6 digits instead of 24 bits for a colour)
  • [1]It is easier for web designers to read and copy without making errors
  • [1]It indicates that the number has been written in hexadecimal format
  • [1]Any one of: MAC addresses, colour codes, URLs, error codes, memory dumps, IPv6 addresses
  • [1]Another from the list above
  • [1]256 possible values for each colour channel (red, green, blue) — from 00 to FF
  • [1]256 × 256 × 256 = over 16 million colours in total
  • [1]Hex is much shorter and easier for programmers to read than long strings of binary
  • [1]It is easier to spot errors and find memory locations when the data is written in hex

6. Binary Addition and Overflow

The 5 Golden Rules of Binary Addition

Binary AdditionBinary AnswerWorking
0 + 00no carry
0 + 11no carry
1 + 01no carry
1 + 10carry 1 (1 + 1 = 2 = 10)
1 + 1 + 11carry 1 (1 + 1 + 1 = 3 = 11)

Start from therightmost digitand move left. Carry over when the sum of a column is greater than 1.

Overflow Explained

  • Anoverflow erroroccurs when the result of a binary additionexceeds the available bits.
  • For an 8-bit register, the maximum value that can be stored is255(binary 11111111).
  • An overflow error will occur if the value is greater than 255 in an 8-bit register.
  • A computer or device has a predefined limit that it can represent or store, for example 16-bit.
  • An overflow error occurs when a value outside this limit should be returned.

Worked Examples

Example 1: 00100111 + 01001010

00100111
+ 01001010
---------
01110001
  • Column 1: 1 + 0 = 1 (no carry)
  • Column 2: 1 + 1 = 0 (carry 1)
  • Column 3: 1 + 0 + 1 = 0 (carry 1)
  • Column 4: 0 + 1 + 1 = 0 (carry 1)
  • Column 5: 0 + 0 + 1 = 1 (no carry)
  • Column 6: 1 + 0 = 1 (no carry)
  • Column 7: 0 + 1 = 1 (no carry)
  • Column 8: 0 + 0 = 0 (no carry)

Example 2: 126 + 62

126 = 01111110
62 = 00111110
+
---------
10111100

10111100 = 128 + 32 + 16 + 8 + 4 = 188, which is the same as 126 + 62.

Overflow Example: 11111111 + 00000001

11111111 (255)
+ 00000001 (1)
---------
100000000 (would need a 9th bit)

In an 8-bit register, the result is00000000— but the correct answer (256) cannot be represented. This is anoverflow error.

Interactive Binary Addition

Enter two 8-bit binary numbers and see the sum with carries.

Activity 6: Binary Addition Practice

Carry out the following binary additions. State whether any cause an overflow.

  1. 00011101 + 01100110
  2. 00100111 + 00111111
  3. 00101110 + 01001101
  4. 01110111 + 00111111
  5. 00111100 + 00110011
  6. 11111111 + 00000001
Solution:
  1. 00011101 + 01100110 =10000011(29 + 102 = 131)
  2. 00100111 + 00111111 =01100110(39 + 63 = 102)
  3. 00101110 + 01001101 =01111011(46 + 77 = 123)
  4. 01110111 + 00111111 =10110110(119 + 63 = 182)
  5. 00111100 + 00110011 =01101111(60 + 51 = 111)
  6. 11111111 + 00000001 =00000000withoverflow error(255 + 1 = 256, needs 9 bits)

Check Your Understanding: Binary Addition

  • [1]1 + 1 = 10 in binary
  • [1]The result is 0 with a carry of 1 to the next column
  • [1]255 (binary 11111111)
  • [1]The result of a calculation is too large to fit in the available number of bits
  • [1]The result needs more bits than the register can hold (e.g. 256 needs 9 bits but an 8-bit register only has 8)
  • [1]Correct addition process with carries
  • [1]= 01111011 (46 + 77 = 123)
  • [1]100000000 has 9 bits, but the register can only store 8 bits
  • [1]This is an overflow error — the correct value (256) cannot be represented in 8 bits
  • [1]126 = 01111110, 62 = 00111110
  • [1]Binary sum = 10111100
  • [1]10111100 = 188, and 126 + 62 = 188 — the results match

7. Logical Binary Shifts

Alogical binary shiftis how a computer system performs basicmultiplication and divisionon non-negative values (0 and positive numbers). Binary digits are moved left or right a set number of times.

Left Shift

  • A left shiftmultipliesa binary number by 2 (×2) per shift
  • Bits shift left; the leftmost bit(s) may be lost (overflow)
  • Empty positions on the right are filled with0
  • A left shift of 2 places multiplies the number by 4 (×4)

Right Shift

  • A right shiftdividesa binary number by 2 (÷2) per shift
  • Bits shift right; the rightmost bit(s) are lost
  • Empty positions on the left are filled with0
  • A right shift of 2 places divides the number by 4 (÷4)

Left Shift Example: 21 → 42 → 84 → 168

Original: 21 = 00010101
128 64 32 16 8 4 2 1
0 0 0 1 0 1 0 1
Left shift 1: 00101010 = 42 (21 × 2¹)
0 0 1 0 1 0 1 0
Left shift 2: 01010100 = 84 (21 × 2²)
0 1 0 1 0 1 0 0
Left shift 3: 10101000 = 168 (21 × 2³)
1 0 1 0 1 0 0 0

Note:If we shift 21 four places left, the leftmost 1-bit is lost, causing an error — this exceeds the maximum shifts for an 8-bit register.

Right Shift Example: 200 → 100 → 50 → 25

Original: 200 = 11001000
1 1 0 0 1 0 0 0
Right shift 1: 01100100 = 100 (200 ÷ 2¹)
0 1 1 0 0 1 0 0
Right shift 2: 00110010 = 50 (200 ÷ 2²)
0 0 1 1 0 0 1 0
Right shift 3: 00011001 = 25 (200 ÷ 2³)
0 0 0 1 1 0 0 1

Note:Shifting four places right loses the rightmost 1-bit and gives an incorrect result (12 instead of 12.5).

Overflow in Binary Shifts

  • Overflow happens when a 1 is shifted out of themost significant bit (MSB)on the left in a logical left shift.
  • This means important data is lost, which can seriously change the number's value.
  • At IGCSE, you usually only need to spot an overflow when a 1 is shifted out on the left.

Interactive Logical Shift

Enter an 8-bit binary number, then shift it left or right.

Activity 7: Logical Shift Practice

  1. Write 24 as an 8-bit register.
  2. Show the result of a logical shift 2 places to the left.
  3. Show the result of a logical shift 3 places to the right.
  4. Write down the denary value of 01101000.
  5. Shift 01101000 three places to the right and comment on your result.
  6. Write down the denary value of 00001111.
  7. Shift 00001111 four places to the left and comment on your result.
Solution:
  1. 24 =00011000
  2. Left shift 2:01100000= 96 (24 × 4)
  3. Right shift 3:00000011= 3 (24 ÷ 8)
  4. 01101000 =104
  5. Right shift 3:00001101= 13 (104 ÷ 8). The rightmost 1-bit is lost, but the result is correct because 104 is divisible by 8.
  6. 00001111 =15
  7. Left shift 4:11110000= 240 (15 × 16). This is still valid because no 1-bits were shifted out of the MSB.

Check Your Understanding: Logical Shifts

  • [1]Each bit is moved one place to the left
  • [1]The value is multiplied by 2; a 0 is inserted at the rightmost position
  • [1]Each bit is moved two places to the right
  • [1]The value is divided by 4; the two rightmost bits are lost and 0s are inserted on the left
  • [1]00000010
  • [1]21 ÷ 8 = 2 (the value 21 is not divisible by 8, so data is lost)
  • [1]When a 1 is shifted out of the most significant bit (MSB) on the left
  • [1]The lost 1-bit means important data is lost, changing the value incorrectly
  • [1]The number is multiplied by 8 (2³)
  • [1]Not always — if a 1-bit is shifted out of the register during the shift, that data is lost permanently
  • [1]This means the reverse shift cannot restore the original value, so the statement is incorrect for numbers where overflow/bit loss occurs

8. Two's Complement (Representing Negative Numbers)

Up until now we have assumed all binary numbers have positive values. To represent both positive and negative numbers, we usetwo's complement. In two's complement, the leftmost bit is designated themost significant bit (MSB)and has anegative value.

Signed Magnitude

  • Leftmost bit = sign bit
  • 0 = positive, 1 = negative
  • Remaining bits = magnitude
  • Has two representations of zero (+0 and −0) — a problem

One's Complement

  • Negative numbers formed byinvertingevery bit of the positive version
  • 0 becomes 1 and 1 becomes 0
  • Still has two representations of zero (+0 = 0000, −0 = 1111)

Two's Complement

  • MSB has anegative value(−128 in 8-bit)
  • Formed by inverting bits of the positive version andadding 1
  • Only one representation of zero — most common method used by computers

Two's Complement in 8 Bits

Column Values

−128
64
32
16
8
4
2
1

If the MSB is 1, the number is negative. If the MSB is 0, the number is positive.

  • Lowest integer: −128
  • Highest integer: +127

Converting to Denary

Example: 10010011
1 0 0 1 0 0 1 1
−128 + 16 + 2 + 1 =−109
Example: 11111111
−128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 =−1

Converting Negative Denary to Two's Complement

Method 1: Put 1s in Correct Places

Convert −79 to 8-bit two's complement
−79 is the same as −128 + 49
49 = 32 + 16 + 1
1 0 1 1 0 0 0 1
Check: −128 + 32 + 16 + 1 = −79 ✓

Method 2: Flip and Add 1

Convert −67 to 8-bit two's complement
Write +67 in binary: 01000011
Invert the bits: 10111100
Add 1: 10111101
−67 = 10111101

Quick Method: Copy from the Right, then Invert

To represent −76:

Write +76 in binary: 01001100
Starting from the LSB (right), copy bits up to and including the first 1: ...100
Invert the remaining bits to the left: 10110100
−76 = 10110100

Interactive Two's Complement Converter

Enter a denary number between −128 and 127 to see its 8-bit two's complement representation.

Activity 8: Two's Complement Practice

Convert the following negative denary numbers into 8-bit two's complement. Use both methods where possible.

  1. −18
  2. −31
  3. −47
  4. −63
  5. −88
  6. −100
  7. −127

Then convert the following two's complement numbers to denary:

  1. 11001110
  2. 10111111
  3. 11101111
  4. 10000111
  5. 11111111
Solution:

Denary to two's complement:

  1. −18 =11101110(18 = 00010010, invert = 11101101, +1 = 11101110)
  2. −31 =11100001(31 = 00011111, invert = 11100000, +1 = 11100001)
  3. −47 =11010001(47 = 00101111, invert = 11010000, +1 = 11010001)
  4. −63 =11000001(63 = 00111111, invert = 11000000, +1 = 11000001)
  5. −88 =10101000(88 = 01011000, invert = 10100111, +1 = 10101000)
  6. −100 =10011100(100 = 01100100, invert = 10011011, +1 = 10011100)
  7. −127 =10000001(127 = 01111111, invert = 10000000, +1 = 10000001)

Two's complement to denary:

  1. 11001110 = −128 + 64 + 8 + 4 + 2 =−50
  2. 10111111 = −128 + 32 + 16 + 8 + 4 + 2 + 1 =−65
  3. 11101111 = −128 + 64 + 32 + 8 + 4 + 2 + 1 =−17
  4. 10000111 = −128 + 4 + 2 + 1 =−121
  5. 11111111 =−1

Check Your Understanding: Two's Complement

  • [1]Lowest value: −128
  • [1]Highest value: +127
  • [1]+1 = 00000001
  • [1]Invert = 11111110, add 1 =11111111
  • [1]MSB is 1, so number is negative: −128
  • [1]−128 + 32 + 16 + 4 =−76
  • [1]In one's complement, you simply invert all the bits of the positive number
  • [1]In two's complement, you invert the bits and then add 1; this removes the duplicate zero representation
  • [1]In 8-bit two's complement, the MSB represents −128 (a negative place value)
  • [1]+104 = 01101000
  • [1]Invert = 10010111, add 1 =10011000

9. Hexadecimal Arithmetic

Just like denary and binary, we can perform arithmetic operations on hexadecimal numbers. You may be asked to add, subtract or multiply hex values in the exam.

Hex Addition

Add the denary values of each digit. If the total is 16 or more, carry 1 to the next column.

C + D = ?
C = 12, D = 13
12 + 13 = 25
25 in hex = 19 (1 sixteen + 9 units)

Hex Subtraction

Subtract the denary values. If the top digit is smaller, borrow 16 from the next column.

8B − 7A = ?
8B = 139, 7A = 122
139 − 122 = 17
17 in hex = 11

Hex Multiplication

Multiply the denary values. Convert the result back to hex.

AA × A = ?
AA = 170, A = 10
170 × 10 = 1700
1700 in hex = 6A4

Hexadecimal Addition: 8B + AA = 135

8B = 1000 1011 = 139 in denary
AA = 1010 1010 = 170 in denary
139 + 170 = 309
309 in hex: 309 ÷ 16 = 19 remainder 5; 19 ÷ 16 = 1 remainder 3; 1 ÷ 16 = 0 remainder 1 →135

Activity 9: Hexadecimal Calculations

Addition:

A + E = ?
D + A = ?
E7 + AB = ?
9F + CB = ?
A5 + EF = ?
99 + EE = ?

Subtraction:

F − B = ?
D − A = ?
E6 − 3B = ?
C2 − A9 = ?
5E − 1C = ?
D1 − 3F = ?

Multiplication:

2 × A = ?
F × F = ?
11 × C = ?
7D × 0A = ?
D8 × 6 = ?
32 × 12 = ?
Solution (selected):

Addition:

  • A + E = 10 + 14 = 24 =18
  • D + A = 13 + 10 = 23 =17
  • E7 + AB = 231 + 171 = 402 =192
  • 9F + CB = 159 + 203 = 362 =16A
  • A5 + EF = 165 + 239 = 404 =194
  • 99 + EE = 153 + 238 = 391 =187

Subtraction:

  • F − B = 15 − 11 = 4 =4
  • D − A = 13 − 10 = 3 =3
  • E6 − 3B = 230 − 59 = 171 =AB
  • C2 − A9 = 194 − 169 = 25 =19
  • 5E − 1C = 94 − 28 = 66 =42
  • D1 − 3F = 209 − 63 = 146 =92

Multiplication:

  • 2 × A = 2 × 10 = 20 =14
  • F × F = 15 × 15 = 225 =E1
  • 11 × C = 17 × 12 = 204 =CC
  • 7D × 0A = 125 × 10 = 1250 =4E2
  • D8 × 6 = 216 × 6 = 1296 =510
  • 32 × 12 = 50 × 18 = 900 =384

Check Your Understanding: Hexadecimal Arithmetic

  • [1]C = 12, D = 13; 12 + 13 = 25 in denary
  • [1]25 in hex = 19
  • [1]8B = 139, 7A = 122; 139 − 122 = 17
  • [1]17 in hex = 11
  • [1]AA = 170, A = 10; 170 × 10 = 1700
  • [1]1700 in hex = 6A4
  • [1]F (since 15 in denary is F in hex)
  • [1]29 in hex = 41 in denary; C8 in hex = 200 in denary
  • [1]41 + 200 = 241 in denary
  • [1]241 in hex = F1. So E1 is not correct — the correct answer is F1.
  • [1]Both work from right to left
  • [1]Both involve carrying when the sum exceeds the base (16 for hex, 2 for binary)

Key Takeaways

  • Computers use binarybecause they are made of switches and logic gates that only have two states: ON (1) and OFF (0). All data must be converted to binary to be processed.
  • Denaryis base 10,binaryis base 2, andhexadecimalis base 16 (using 0–9 and A–F).
  • One hex digit = 4 bits (one nibble).Two hex digits = 8 bits (one byte).
  • When convertingdenary to binary, use place value columns or repeated division by 2. When convertingbinary to denary, add the column values where there is a 1.
  • Convertbinary to hexby splitting into nibbles and converting each nibble to its hex digit.
  • Hexadecimal is used forMAC addresses(6 pairs of hex digits),colour codes(#RRGGBB),URLs(% prefix),error codes,memory dumps, andIPv6 addresses.
  • Inbinary addition: 0+0=0, 0+1=1, 1+0=1, 1+1=0 carry 1, 1+1+1=1 carry 1.
  • Overflowoccurs when the result of a binary addition exceeds the available bits (e.g. >255 in an 8-bit register).
  • Alogical left shiftmultiplies by 2 per shift (×2, ×4, ×8). Alogical right shiftdivides by 2 per shift (÷2, ÷4, ÷8).
  • Overflow in a left shift occurs when a 1 is shifted out of the MSB.
  • Two's complementrepresents negative numbers. In 8-bit, the MSB has a value of −128. Range: −128 to +127.
  • To find two's complement of a negative number: write the positive binary, invert the bits, and add 1.
  • 1 KiB = 1024 bytes(binary/IEC) and1 KB = 1000 bytes(decimal/SI). Internal memory (RAM) should be measured using IEC units.

Question Bank

  • [1]Computers process data using logic gates...
  • [1]... that can only have two states (1/0)
  • [1]00111011 (32 + 16 + 8 + 2 + 1 = 59)
  • [1]1024 + 512 + 128 + 16 + 1
  • [1]= 1681
  • [1]Split 01010000: 0101 | 0000
  • [1]0101 = 5, 0000 = 0 →50
  • [1]Split 00111101: 0011 | 1101
  • [1]0011 = 3, 1101 = D →3D
  • [1]Used to identify a device on a network
  • [1]It is a unique address
  • [1]It is a static address / it does not change
  • [1]It is set by the manufacturer; the first part is the manufacturer ID and the second part is the serial number
  • [1]Correct addition with carries shown
  • [1]= 10100010 (25 + 137 = 162)
  • [1]An overflow error occurs when the result of a calculation is too large to be stored
  • [1]It happens when the value exceeds the maximum that can be represented with the available bits (e.g. >255 in 8-bit)
  • [1]For example, 11111111 + 00000001 causes overflow because 256 needs 9 bits
  • [1]01100000
  • [1]96 (24 × 4 = 96)
  • [1]+49 = 00110001; invert = 11001110; add 1 = 11001111
  • [1]11001111
  • [1]MSB is 1, so number is negative: −128
  • [1]−128 + 4 + 2 + 1 =−121
  • [1]Hex is much shorter and easier to read than long strings of binary
  • [1]It reduces the chance of copying errors and makes it easier to spot where an error has occurred
  • [1]1 KB = 1 000 bytes (decimal/SI)
  • [1]1 KiB = 1 024 bytes (binary/IEC)
  • [1]Hours: 00000101 = 5
  • [1]Minutes: 00011010 = 26
  • [1]Seconds: 00110111 = 55
  • [1]5 × 16 = 80; F (15) × 1 = 15; 80 + 15 = 95 in denary
  • [1]5 = 0101, F = 1111
  • [1]Binary = 01011111
  • [1]The result would be 00001100
  • [1]200 ÷ 16 = 12.5, but the result is only 12
  • [1]This is because the rightmost 1-bit is lost during the shift, causing an error (loss of data)