It is useful to remember the capacity of a standard 8-bit byte:
Smallest value:00000000 (0)
Largest value:11111111 (255)
Total combinations: $2^8 = 256$ different values.
Hexadecimal System (Base-16)
Watch this lesson
Video 1.1.3 ·
6:56 · Base 16, why programmers use it, and converting both ways
1. The Hexadecimal Concept
Hexadecimal is a Base-16 system. Because we only have 10 digits (0-9) in our standard alphabet, we use letters to represent values from 10 to 15.
Denary
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
2. Converting Binary to Hexadecimal
This is the most common task in IGCSE exams. It works because $16$ is a power of $2$ ($2^4 = 16$). One Hex digit represents exactly 4 bits (a nibble).
Method: The 4-Bit Grouping
Take a binary string (e.g., 10110110).
Split it into two 4-bit nibbles: 1011 and 0110.
Convert each nibble to Denary:
1011 = $8 + 2 + 1 = 11$
0110 = $4 + 2 = 6$
Convert those values to Hex:
$11$ becomes B
$6$ remains 6
Final Answer: B6
3. Converting Hexadecimal to Denary
Just like Binary and Denary, Hex uses place values. However, the multipliers are powers of 16.
Example: Convert 2A to Denary
Write the place values: 16s and 1s.
$(2 \times 16) + (A \times 1)$
Since $A = 10$, the calculation is: $(2 \times 16) + (10 \times 1)$
$32 + 10 = 42$
Result: 42
4. Practical Applications in CS
You may be asked where Hex is used in the real world. Memorize these three:
MAC Addresses: Media Access Control addresses (e.g., 00:1A:2B:3C:4D:5E).
HTML/CSS Color Codes: Using RGB values (e.g., #FF5733).
Memory Dumps / Debugging: Displaying the contents of RAM to help programmers find errors.
Assembly Language: To represent machine code instructions in a readable way.
5. Common Pitfall: Storage Myth
⚠️ Exam Warning:
Hexadecimal does not save storage space. Computers never store data as Hex; they convert everything back to Binary (1s and 0s) for processing. Hex is strictly for human readability.
Binary Addition and Overflow
Watch this lesson
Video 1.1.4 ·
8:00 · Adding bits, carrying, and what happens when a byte runs out of room
1. The Four Rules of Binary Addition
Binary addition follows the same logic as denary addition (carrying values to the next column), but you only have two digits to work with.
$0 + 0 = 0$
$0 + 1 = 1$
$1 + 1 = 10$ (0 carry 1)
$1 + 1 + 1 = 11$ (1 carry 1)
2. Addition Example
When adding binary numbers, always start from the Right (the Least Significant Bit).
111 (Carries)
01101010 (106)
+00011100 (28)
10000110 (134)
3. Overflow Errors
In IGCSE Computer Science, we usually work with 8-bit registers. An 8-bit register can store a maximum value of 255 ($11111111$).
Definition: An Overflow Error occurs when the result of a binary addition exceeds the maximum capacity of the register (e.g., the result needs 9 bits but only 8 are available).
Example of Overflow:
Attempting to add $150 + 150$ in an 8-bit register:
11
10010110 (150)
+ 10010110 (150)
100101100 (300)
The 9th bit (highlighted in red) has nowhere to go. The CPU simply drops it.
4. Consequences of Overflow
Data Loss: The computer "ignores" the extra bit, leading to an mathematically incorrect result (e.g., $150+150$ might appear to equal $44$).
System Crashes: In some cases, an unexpected overflow can cause a program to crash or behave unpredictably.
Security Risks: Hackers sometimes use "Buffer Overflows" to gain control of a system by forcing data into memory it shouldn't access.
5. Logical Binary Shifts
Shifting moves every bit left or right. Each place left multiplies a positive number by 2. Each place right divides it by 2 and throws away the remainder. Any bit pushed off the end is lost.
For worked examples and the limitations you need for the exam, see Logical Binary Shifts.
1 + 1 is 10, not 2!
Logical Binary Shifts
Watch this lesson
Video 1.1.5 ·
9:55 · Multiplying and dividing by moving bits — and exactly when it stops working
A logical binary shift slides every bit in a register left or right. It is the fastest way a processor can multiply or divide a positive whole number by 2, 4, 8, 16… It also has firm limits: bits that slide off the end are gone for good. You need to be able to perform a shift on an 8-bit positive integer, state the effect it has on the number, and say when that effect breaks down.
1. What a logical shift does
Definition
A logical shift moves every bit in a binary number the same number of places to the left or to the right. Positions left empty are filled with 0. Any bit pushed past either end of the register is lost.
Three rules cover every logical shift question:
Every bit moves the same number of places in the same direction. The pattern itself does not change; only its position does.
The gap is filled with 0. A left shift feeds zeros in at the right-hand end (the least significant bit, LSB). A right shift feeds zeros in at the left-hand end (the most significant bit, MSB).
Bits that fall off the end are discarded. The register is still exactly 8 bits wide after the shift, so whatever does not fit is thrown away.
2. Logical left shift: multiply by 2
Figure 1 — A left shift moves each bit into the next column up, so every 1 is worth twice as much as before.
Each column in binary is worth twice the column to its right. Moving every bit one column to the left therefore doubles the value of every 1, and so doubles the whole number. Here the bit that fell off the left-hand end was a 0, so nothing of value was lost and the answer is exactly right.
Shift 0010 0110 (38) left by 2 places
0010 0110 38
1001 1000 152 every bit moved 2 places left, two 0s fed in at the righteffect: 38 x 2 x 2 = 38 x 4 = 152
3. Logical right shift: divide by 2
Figure 2 — A right shift halves the value of every 1. The 1 that fell off the right was worth ½, so the remainder is lost.
Moving every bit one column to the right halves the value of each 1. For an even number the answer is exact. For an odd number the LSB is a 1, worth ½ after the shift, and there is no column to hold it. It is discarded, so the result is the answer rounded down to a whole number. This is integer division: 183 ÷ 2 gives 91, and the remainder 1 is thrown away.
4. Shifting more than one place
Each place doubles or halves the number once, so a shift of n places multiplies or divides by 2 a total of n times.
Places shifted
Left shift multiplies by
Right shift divides by
1
2
2
2
4 (2 × 2)
4
3
8 (2 × 2 × 2)
8
4
16
16
n
2n
2n, remainder discarded
The tables below follow one number through several shifts. Watch the last column: the effect holds until a 1 drops off the end, and then it breaks.
0000 1101 (13) shifted left
Places
Result
Denary
Correct?
1
0001 1010
26
13 × 2
2
0011 0100
52
13 × 4
3
0110 1000
104
13 × 8
4
1101 0000
208
13 × 16
5
1010 0000
160
should be 416
1011 0110 (182) shifted right
Places
Result
Denary
Exact answer
1
0101 1011
91
91
2
0010 1101
45
45.5
3
0001 0110
22
22.75
4
0000 1011
11
11.375
5. The limitations of logical shifting
A shift is only a reliable multiply or divide while no 1s are lost. These are the limits the exam expects you to recognise.
1. Left shifts can overflow
If a 1 is shifted out of the MSB, the answer is too big for 8 bits and the result is wrong. Above, 13 shifted left 5 places should be 416, which needs 9 bits, so 160 is stored instead.
A left shift of n places is only safe if the n leftmost bits are all 0.
2. Right shifts lose precision
If a 1 is shifted out of the LSB, a fraction is thrown away and the result is rounded down. 0001 0111 (23) shifted right 2 places gives 0000 0101 (5), not 5.75.
The result is only exact if the n rightmost bits are all 0.
3. Lost bits cannot be recovered
A shift cannot simply be undone by shifting back. The lost bit is replaced by a 0, not restored:
1100 0011 (195) → left 1 → 1000 0110 → right 1 → 0100 0011 (67)
4. Powers of 2 only
A shift can only multiply or divide by 2, 4, 8, 16… Multiplying by 3, 5 or 10 cannot be done with a single shift. A processor would combine shifts with addition instead: x × 10 is (x shifted left 3) + (x shifted left 1).
5. Positive integers only
A logical right shift always puts a 0 into the MSB. In two’s complement the MSB is the sign bit, so a negative number becomes positive. 1111 1000 (−8) shifted right 1 gives 0111 1100 (+124), not −4. See the next lesson for two’s complement.
6. Shift too far and nothing is left
Shifting an 8-bit number 8 or more places in either direction pushes every original bit out, leaving 0000 0000 whatever the starting value.
6. Why computers use shifts
Speed. A shift is one of the simplest things a processor can do, usually far quicker than a general multiply or divide. Compilers routinely replace “× 8” with “shift left 3”.
Moving bits into position. Shifts line a group of bits up with the place they need to go, for example when packing several small values into one byte or when reading sensor data one bit at a time.
Exam technique Always write the result as a full 8-bit number, padding with 0s. When asked for the effect, give the operation and the factor (“multiplied by 4”, not just “bigger”). If a 1 was shifted out, say so: that is the mark for the limitation. Name the bits correctly too: the MSB is on the left, the LSB is on the right.
7. Check yourself
Perform a logical left shift of 2 places on 0011 0101. Give the denary value before and after, and state the effect.
Result: 1101 0100. Before: 53. After: 212. The number has been multiplied by 4 (22), and 53 × 4 = 212 exactly because the two bits shifted out of the MSB were both 0.
Perform a logical right shift of 3 places on 1100 1010. Is the result an exact division?
Result: 0001 1001 = 25. The original was 202, and 202 ÷ 8 = 25.25. The result is not exact: the bits 010 shifted out of the LSB end included a 1, so the remainder (0.25) was lost and the answer was rounded down.
1001 0000 (144) is shifted left by 1 place. Explain why the result is not 288.
The result is 0010 0000 = 32. The MSB was a 1, which was shifted out of the 8-bit register and lost. 288 needs 9 bits and cannot be stored in 8, so the shift produced an overflow and an incorrect result.
State the type of shift, and the number of places, that divides a positive binary integer by 16.
A logical right shift of 4 places, because 24 = 16. Any remainder is discarded.
0110 1101 is shifted right 1 place and then left 1 place. Explain why the final value is not the original value. [2]
The right shift gives 0011 0110 (54) and the left shift then gives 0110 1100 (108), not 109. The LSB of the original was a 1, and it was lost during the right shift. The left shift feeds in a 0 in its place, so the lost bit cannot be recovered.
Give two limitations of using logical shifts to perform multiplication and division. [2]
Any two of: a left shift causes an overflow and a wrong result if a 1 is shifted out of the MSB; a right shift loses the remainder (rounds down) if a 1 is shifted out of the LSB; shifts can only multiply or divide by powers of 2; logical shifts are only correct for positive integers, because a right shift puts 0 into the sign bit of a negative two’s complement number.
Two's Complement and Binary Subtraction
Watch this lesson
Video 1.1.6 ·
13:06 · Negative numbers in eight bits, the shortcut, and subtracting by adding
So far every binary number has been positive. To store negative numbers, the 256 patterns of an 8-bit register have to be shared between positive and negative values. One’s complement is the obvious first attempt and it has two flaws. Two’s complement fixes both, and it lets a computer subtract by adding. There is also a shortcut that turns the two-step conversion into one pass.
1. The problem: where does the minus sign go?
A register holds only 0s and 1s. There is no space for a “−” symbol, so the sign has to be shown by the bits themselves. Both systems below use the same idea: if the most significant bit (MSB) is 1, the number is negative. They differ in how the remaining bits are worked out.
2. One’s complement
Definition
In one’s complement, a negative number is made by inverting every bit of the positive number: every 0 becomes 1 and every 1 becomes 0.
+18 0001 0010
-18 1110 1101 every bit flipped. The MSB is now 1, so the number is negative
It is easy to do, but it causes two problems:
Two zeros
0000 0000 is +0, and inverting it gives 1111 1111, which is −0. One of the 256 patterns is wasted on a duplicate. Every comparison with zero also has to check for both patterns.
Range in 8 bits: −127 to +127.
Addition needs a fix-up step
When adding a negative number produces a carry out of the MSB, that carry has to be added back on at the right-hand end (an end-around carry) before the answer is correct. That means a second addition, and extra circuitry.
One's complement: 5 + (−3)1 1111 1 carries
0000 0101 +5
+ 1111 1100 −3 (3 = 0000 0011, inverted)
----------
1 0000 0001 carry out of the MSBadd the carry back on at the right ("end-around carry")
+ 0000 0001
----------
0000 0010= +2, but only after a second addition
3. Two’s complement
Definition
In two’s complement, a negative number is made by inverting every bit of the positive number (the one’s complement) and then adding 1. Equivalently, the MSB has a place value of −128 instead of +128.
Figure 1 — Reading 1110 1110 using place values. Only the MSB column is negative.
Adding 1 after inverting removes the duplicate zero. Inverting 0000 0000 gives 1111 1111, and adding 1 gives 1 0000 0000. The 9th bit is discarded, leaving 0000 0000 again. There is now only one zero, so the spare pattern holds an extra negative number: 1000 0000 is −128.
8-bit pattern
Unsigned
One’s complement
Two’s complement
0111 1111
127
+127
+127 (largest)
0000 0001
1
+1
+1
0000 0000
0
+0
0
1111 1111
255
−0
−1
1111 1110
254
−1
−2
1000 0001
129
−126
−127
1000 0000
128
−127
−128 (smallest)
Converting denary to 8-bit two’s complement
Write the positive version of the number in 8-bit binary, padded with leading 0s. (If the number is positive, stop here. The MSB must be 0.)
For a negative number, invert every bit.
Add 1. Ignore any carry out of the MSB.
Converting 8-bit two’s complement to denary
MSB is 0: the number is positive. Read it as ordinary binary.
MSB is 1: the number is negative. Either add up the place values using −128 for the MSB (Figure 1), or find its two’s complement again to get the positive size, then put a minus sign in front.
Why two’s complement won It has one zero, it holds one more value (−128 to +127), and ordinary binary addition gives the right answer for any mix of positive and negative numbers with no fix-up step: a carry out of the MSB is simply thrown away. Compare the two’s complement sum below with the one’s complement sum in section 2.
Two's complement: 5 + (−3)1 1111 1 1 carries
0000 0101 +5
+ 1111 1101 −3 (3 = 0000 0011, invert, add 1)
----------
1 0000 0010 carry out of the MSB0000 0010discard the carry: 0000 0010 = +2, done
4. The shortcut
Look closely at what happens when you invert and then add 1. The figures below find −104 both ways.
Figure 2 — After adding 1, the green bits are back to exactly what they were in the original number.
The observation: the original number ends in 1000, its first 1 from the right followed by zeros. Inverting turns that into 0111. Adding 1 to 0111 carries all the way through the 1s and stops at the 0, giving 1000 again. So the bits up to and including the first 1 come out unchanged, and the carry never reaches the bits to their left, which stay inverted. That is true for any number, which gives the shortcut:
The shortcut
Working from the right, copy every bit up to and including the first 1. Then invert every bit to the left of it.
Figure 3 — Same answer as Figure 2, with no addition and no carries to keep track of.
It works both ways
Apply it to a negative number to get the positive one back. 1110 1110 → copy 10, invert the rest → 0001 0010 = 18, so the original was −18.
Edge case: zero
0000 0000 has no 1 to stop at, so every bit is copied and the result is still 0. There is no −0, as expected.
Edge case: −128
1000 0000 → copy 1000 0000 (the first 1 is the MSB) → unchanged. +128 does not exist in 8 bits, so −128 has no positive partner.
Use the shortcut, then check with place values The shortcut is quick but easy to misapply under pressure. Add the place values of your answer using −128 for the MSB. It takes ten seconds and catches nearly every slip.
5. Binary subtraction using two’s complement
A processor does not need a separate circuit for subtraction. Taking away a number is the same as adding its negative:
MethodA − B = A + (−B). Find the two’s complement of B, add it to A using ordinary binary addition, and discard any carry out of the MSB.
Example 1: 45 − 18 = 45 + (−18)1 11 1 1 carries
0010 1101 +45
+ 1110 1110 −18
----------
1 0001 1011 carry out of the MSB0001 1011discard the carry: 0001 1011 = +27 ✓
The carry out of bit 7 is discarded. It is not an error. With two’s complement a carry out of the MSB is a normal part of adding a negative number.
Example 2: 20 − 50 = 20 + (−50) 11 1 carries
0001 0100 +20
+ 1100 1110 −50
----------
1110 0010no carry out; MSB is 1, so the answer is negative
The answer 1110 0010 starts with 1, so it is negative. To read it, use the shortcut: copy 10, invert 111000 to 000111, giving 0001 1110 = 30. The answer is −30 ✓.
Example 3: −20 − 30 = (−20) + (−30)1 11 carries
1110 1100 −20
+ 1110 0010 −30
----------
1 1100 1110 carry out of the MSB1100 1110discard the carry: 1100 1110 = −50 ✓
Overflow in two’s complement
The result of a subtraction must still fit in the range −128 to +127. If it does not, the answer is wrong, and a carry out tells you nothing about it. Example 1 and Example 3 both had a carry out and both answers were correct.
−100 − 50 = (−100) + (−50)1 11 1 carries
1001 1100 −100
+ 1100 1110 −50
----------
1 0110 1010 carry out of the MSB0110 1010discard the carry: 0110 1010 = +106 ✗ WRONG
How to spot overflow Adding two numbers of the same sign can never legitimately give a result of the opposite sign. Here two negatives (MSB 1) produced a positive (MSB 0). The real answer, −150, is below −128 and cannot be stored in 8 bits. Adding a positive and a negative number can never overflow.
6. One’s complement vs two’s complement
One’s complement
Two’s complement
To negate
Invert every bit
Invert every bit, then add 1 (or use the shortcut)
MSB place value
−127
−128
8-bit range
−127 to +127
−128 to +127
Representations of zero
Two (+0 and −0)
One
Carry out of the MSB
Must be added back on (end-around carry)
Discarded
Used in modern computers?
Rarely
Almost universally for signed integers
Exam scope At IGCSE you must be able to convert positive and negative denary integers to and from 8-bit two’s complement. Binary subtraction using two’s complement is examined directly at AS Level (9618 topic 1.1). It is included here because it shows why two’s complement is designed the way it is.
7. Check yourself
Convert −45 to 8-bit two’s complement.
45 = 0010 1101. Using the shortcut: the first 1 from the right is the LSB, so copy just that 1 and invert the other seven bits: 1101 0011. Check: −128 + 64 + 16 + 2 + 1 = −45 ✓.
1011 0100 is an 8-bit two’s complement integer. Convert it to denary.
The MSB is 1, so it is negative. Place values: −128 + 32 + 16 + 4 = −76. Check with the shortcut: copy 100, invert 10110 to 01001, giving 0100 1100 = 76, so the original was −76 ✓.
Use the shortcut to find the two’s complement of 0101 0000.
Copy up to and including the first 1 from the right: 10000. Invert the remaining 010 to 101. Result: 1011 0000. Check: −128 + 32 + 16 = −80, and 0101 0000 is 80 ✓.
Explain why one’s complement has two representations of zero, and why this is a disadvantage. [2]
Negating a number in one’s complement inverts every bit, so +0 (0000 0000) becomes 1111 1111, a second pattern meaning −0. This wastes one of the 256 patterns, so the range is only −127 to +127. It also means a test for zero has to check for two different patterns.
Calculate 37 − 52 using 8-bit two’s complement. Show your working.
37 = 0010 0101. 52 = 0011 0100, so −52 = 1100 1100 (copy 100, invert the rest). Add: 0010 0101 + 1100 1100 = 1111 0001, with no carry out. The MSB is 1, so the answer is negative. Copy 1 and invert the rest to get 0000 1111 = 15. The answer is −15 ✓.
State the largest and smallest values in 8-bit two’s complement, and explain why the range is not symmetrical.
Largest +127 (0111 1111), smallest −128 (1000 0000). Half of the 256 patterns have an MSB of 0, and they cover 0 to +127. Zero uses one of them, leaving 127 positive numbers. The other 128 patterns all have an MSB of 1 and are all negative, covering −1 to −128.
Calculate 90 − (−50) in 8-bit two’s complement and comment on the result. [3]
Subtracting −50 is the same as adding +50: 0101 1010 + 0011 0010 = 1000 1100. The MSB is 1, so the stored result reads as −128 + 8 + 4 = −116. The correct answer is 140, which is greater than +127 and cannot be represented in 8 bits. Two positive numbers have given a negative result, so an overflow has occurred.