Edexcel GCSE Computer Science (1CP2) · Data › Data representation
Practise Characters and ASCII. 12 exam-style questions plus unlimited generated ones on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.
Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.
State the number of different characters that can be represented using 7-bit ASCII.
128
State why each character in a character set must have a unique binary code.
So every code stands for exactly one character and is always displayed correctly.
The ASCII codes for 'a' to 'z' are 97 to 122, and the codes for 'A' to 'Z' are 65 to 90. This Python program changes the letters in a word.
01 word = input("Enter a word: ")
02 result = ""
03 for letter in word:
04 code = ord(letter)
05 if code >= 97 and code <= 122:
06 code = code - 32
07 result = result + chr(code)
08 print(result)
State the output when the user enters Hi5x.
HI5X
A program sorts words into order by comparing the ASCII codes of their characters, one character at a time from the left. The ASCII code for 'A' is 65, for 'a' is 97 and for '0' is 48. State the ASCII codes for 'Z' and for 'a'.
'Z' = 90, 'a' = 97
In 7-bit ASCII, the character '0' has the code 48, and the characters '0' to '9' have consecutive codes. State the ASCII code for the character '7'.
55
Sample questions
Written for this site in the style of Edexcel exam questions. They are not taken from real past papers.
Question 1Easy3 marks
(a) State the number of different characters that can be represented using 7-bit ASCII.[1]
(b) The ASCII code for 'M' is 77. State the ASCII code for 'P'.[1]
(c) Identify the best description of a character set.[1]
A list of characters that a computer can represent, each with its own unique binary code
The keys on a computer keyboard
A style of lettering used to display text on a screen
The number of characters in a string
Show the answer and mark scheme
(a)Answer: 128
128 (27)
(b)Answer: 80
80
(c)Answer: A list of characters that a computer can represent, each with its own unique binary code
Question 2Medium4 marks
In ASCII, the character '0' has the code 48 (011 0000 in 7-bit binary). The digits '0' to '9' have consecutive codes.
(a) Give the 7-bit ASCII code for the character '6'.[1]
(b) A user types 25 into a text box. The program stores it as a string of two characters. Give the denary ASCII codes that are stored.[1]
(c) Explain why these codes are different from the binary representation of the integer 25.[2]
Show the answer and mark scheme
(a)Answer: 011 0110
011 0110 (54)
(b)Answer: 50, 53
50 and 53 (in that order)
(c)Answer: The string stores a code for each digit character; the integer 25 is stored as the binary number 0001 1001, so the text must be converted before doing arithmetic.
each digit is stored as a separate character code ('2' = 50, '5' = 53), not as a number
the integer 25 would be stored as its binary value (0001 1001), so the string must be converted to an integer, e.g. with int(), before it can be used in calculations
Question 3Hard4 marks
In ASCII, 'G' has the code 100 0111 (71) and 'g' has the code 110 0111 (103).
(a) State the difference between the denary codes of 'G' and 'g'.[1]
(b) Explain how a program could use ASCII codes to convert any lower-case letter to upper case.[2]
(c) Give a reason why the program should check that a character is a lower-case letter before converting it.[1]
Show the answer and mark scheme
(a)Answer: 32
32
(b)Answer: Subtract 32 from its code (clear the 32 bit), because each lower-case code is 32 more than the upper-case code.
subtract 32 from the ASCII code of the letter / change the bit with place value 32 from 1 to 0
because the code of every lower-case letter is exactly 32 more than the code of the matching upper-case letter
(c)Answer: Otherwise other characters are corrupted, e.g. 'A' (65) would become '!' (33).
other characters would be changed into the wrong characters, e.g. 'A' (65) would become '!' (33)