Information representation

Information representation

Character sets: ASCII and Unicode

Data Representation AS Level 20 min read

On this page
  1. What you need to be able to do
  2. What a character set is
  3. ASCII and extended ASCII
  4. Unicode
  5. Working with character codes
  6. Mark-scheme focus
  7. Worked examples
  8. Summary
  9. Can I do this?
  10. Quiz

What you need to be able to do

Syllabus 1.1 Data representation
  • 1.1Explain what a character set is and how text is represented in binary, character by character.
  • 1.1Describe ASCII, extended ASCII and Unicode: bits per character, how many characters, what they can represent.
  • 1.1Compare the character sets (similarities and differences) and justify using one.
  • 1.1Work with character codes: convert a given code between denary, binary and hex, and find a neighbouring character's code.

You need: binary, denary and hex conversions from Number bases, prefixes and BCD. You will not be asked to remember any particular code: the question always gives you one to work from.

What a character set is

A character set is all the characters / symbols that a computer can use (represent), where each character has a unique number (binary code).

Text is stored by replacing every character, including spaces and punctuation, with its code. For the word “Cat” in ASCII:

CharacterCat
Denary code6797116
Binary (stored)0100 00110110 00010111 0100
Hex436174
  1. Each character has its own unique code in the character set.
  2. Each character in the text is replaced by its code (stored in binary).
  3. The codes are stored in sequence, in the same order as the characters in the text.

Those three points are exactly how the mark scheme words “explain how the word … is represented”. The examiner's comment (June 2021): the two ideas that were needed are uniqueness and order; “each character has a code” is not precise enough.

ASCII and extended ASCII

ASCIIExtended ASCII
Bits per character7 (usually stored in an 8-bit byte with the extra bit 0)8
Number of characters\(2^7=128\) (codes 0-127)\(2^8=256\) (codes 0-255)
What it coversEnglish letters (upper and lower case), digits, punctuation, and non-printing control codes (e.g. 13 = carriage return)all of ASCII (codes 0-127 are identical) plus 128 more: accented letters (é, ü), extra symbols, line-drawing characters
LimitationEnglish (Latin alphabet) onlystill only 256 characters: not enough for Chinese, Arabic, Urdu, emoji …; different “code pages” used the top 128 codes differently

Codes for letters and digits run in order, so one given code lets you work out its neighbours:

GroupPattern (example codes - you won't need to memorise them)
Upper-case lettersA = 65, B = 66 … Z = 90 (consecutive)
Lower-case lettersa = 97 … z = 122: each is 32 more than its capital (one bit different: 0100 0001 vs 0110 0001)
Digits'0' = 48 … '9' = 57: the character '5' (code 53) is not the number 5
Space32
A common slip (June 2021): extended ASCII has 256 characters, not 255. 255 is the largest code; with code 0 there are 256.

Unicode

Unicode was designed to give every character in every language its own unique code, plus symbols and emoji, so that text looks the same on every computer in every country.

Unicode
Bits per character16 or 32 (the common encodings use 8, 16 or 32 bits per character: UTF-8, UTF-16, UTF-32)
Number of characters65 536 or more (16 bits); over a million possible codes in all
What it coverscharacters from (almost) all languages, mathematical and other symbols, emoji
Link with ASCIIthe first 128 Unicode codes are the ASCII codes: ASCII is a subset of Unicode

ASCII vs Unicode

ASCII / extended ASCIIUnicode
Bits per character7 / 8up to 32 (16 or 32 commonly)
Characters128 / 25665 536+
LanguagesEnglish / Western European onlyvirtually all languages
Storage per characterless (1 byte)more (2-4 bytes), so text files are larger

Similarities to quote

Both represent each character using a unique code; both can use 8 bits; Unicode contains all the ASCII characters (ASCII is a subset).

Why choose Unicode

A wider range of characters, so text in more languages (and emoji / symbols) can be represented, and shared internationally without garbling.

Why choose ASCII

Fewer bits per character, so a smaller file, when only English characters are needed.

Working with character codes

1 A neighbouring code

In a character set the code for 'D' is 68. What is the code for 'H'?

Askedcode of HKnowletters are consecutiveRoutecount on from D

  1. D, E, F, G, H: 4 letters later
  2. 68 + 4 = 72

2 Digit character from a given one

The code for the character '1' is 49 (denary). Give the code for '7' in hexadecimal.

Askedhex code of '7'Knowdigits are consecutiveRoute49 + 6, then hex

  1. '7' is 6 after '1': 49 + 6 = 55
  2. 55 = 3 × 16 + 7 = 37 hex

3 Lower case from upper case

The code for 'M' is 0100 1101. Give the code for 'm' in binary.

Askedbinary code of 'm'Knowlower case = upper case + 32Routeset the 32s bit

  1. 32 = 0010 0000
  2. 0100 1101 + 0010 0000 = 0110 1101

Adding 32 just switches on the 32s bit, because that bit is 0 in every capital letter.

4 A Unicode code in hex to denary

A Unicode character has the code 03A9 (hex). What is it in denary?

AskeddenaryKnowhex place valuesRoute0 × 4096 + 3 × 256 + 10 × 16 + 9

  1. 768 + 160 + 9 = 937

5 Storage for some text

How many bytes does the 20-character text “Topical past papers!” take in extended ASCII and in 16-bit Unicode?

AskedbytesKnow8 bits vs 16 bits per characterRoutecharacters × bits ÷ 8

  1. Extended ASCII: 20 × 8 bits = 160 bits = 20 bytes
  2. 16-bit Unicode: 20 × 16 bits = 320 bits = 40 bytes

Spaces and punctuation are characters too: count them.

Mark-scheme focus

“Describe what is meant by a character set” (2 marks)

9618/13/M/J/22 Q1Paper 1 · Theory fundamentalsPart (a)(i)2 marksFull size
Text and numbers are examples of data stored in a computer. (a) A character set is used to represent characters in a computer. (i) Describe what is meant by a character set. [2]
Credited
  • All of the characters / symbols that the computer can use / represent B1
  • Each character has a unique number / binary number / hexadecimal number B1
Not credited
  • “A character set is a set of characters” (repeats the question)
  • “Each character has a code” (not unique)
Why

Two marks need two different points: what the set contains, and the one-to-one link between each character and its code (June 2022 report).

From: 9618/13/M/J/22 Q1(a)(i)

“Explain how the word ‘Clock’ is represented by a character set” (2 marks)

9618/13/M/J/24 Q1Paper 1 · Theory fundamentalsPart (d)(ii)2 marksFull size
(d) Computers use character sets when representing characters in binary. (ii) Explain how the word 'Clock' is represented by a character set. [2]
Credited
  • Each character has a unique binary code B1
  • The binary code for each character is stored in sequence (in the order of the word) B1
Not credited
  • “Clock is converted into binary” (how?)
  • “Each letter has a code” (unique is missing)
  • Listing ASCII codes you can't be sure of
Why

The scheme wants the mechanism: unique code per character, codes stored in the word's order. You never need the actual codes.

From: 9618/13/M/J/24 Q1(d)(ii)

“Give one similarity and two differences between ASCII and Unicode” (3 marks)

9618/11/O/N/22 Q1Paper 1 · Theory fundamentalsPart (c)3 marksFull size
(c) Give one similarity and two differences between the ASCII and Unicode character sets. Similarity … Difference 1 … Difference 2 … [3]
Credited
  • Similarity: both represent each character using a unique code // both can use 8 bits // ASCII is a subset of Unicode B1
  • Difference: Unicode can use up to 32 bits per character, ASCII 7 or 8 B1
  • Difference: Unicode can represent a wider range of characters / different languages; ASCII only one language B1
Not credited
  • “Unicode is better” / “ASCII is older”
  • Two differences that say the same thing (more bits AND more characters can count as one idea if not expanded - give two distinct points)
Why

Each difference must compare both sets on one feature: bits per character, number of characters, languages covered.

From: 9618/11/O/N/22 Q1(c)

  • One character-set question in most papers: 1-5 marks, often attached to a file or a multimedia question.
  • Commonest asks: describe a character set (2), how a word is stored (2), ASCII vs Unicode (2-3), bits / characters in each (1-2).
  • Code arithmetic: a given code → a neighbour's code, or the code converted to hex / binary / BCD (1 mark each).

Worked examples

Example 1 · ASCII, a word, and Unicode codes (Paper 1, 6 marks) ★ Easy
9618/12/M/J/21 Q6Paper 1 · Theory fundamentals6 marksFull size
A computer uses the ASCII character set. (a) State the number of characters that can be represented by the ASCII character set and the extended ASCII character set. [2] (b) Explain how a word such as 'HOUSE' is represented by the ASCII character set. [2] (c) Unicode is a different character set. The Unicode value for the character '1' is denary value 49. (i) Write the hexadecimal value for the Unicode character '1'. [1] (ii) Write the denary value for the Unicode character '5'. [1]
1 Read it with me what is actually happening?

Three skills in one question: facts about ASCII, how text is stored, and code arithmetic from one given code.

  • number of characters\(2^{\text{bits}}\)
  • explain how … representedunique code + in sequence
  • hexadecimal valueconvert 49
  • denary value for '5'count on from '1'
2 What is it asking for? the target, part by part
  • (a)128 and 2562
  • (b)how HOUSE is stored2
  • (c)(i)49 in hex1
  • (c)(ii)code of '5'1
3 What do we know? everything the question gives us
  • ASCII 7 bits, extended 8
  • '1' = 49
  • digit characters have consecutive codes
4 Plan the route work backwards from what we want
FindKey ideaAlready have itWork out firstTrap
  • (c)(ii)'5'
    • Consecutive'5' is 4 after '1'
    • Trapanswering in binary
49 in hex?

49 = 3 × 16 + 1 → 31.

Which answers are in which base?

(c)(i) hex, (c)(ii) denary: the report saw binary answers to both.

5 Now solve it have a go on paper first, then open the worked solution
  1. (a) ASCII: 128 // \(2^7\) B1; extended ASCII: 256 // \(2^8\) B1
  2. (b) Each character has its own unique code B1; each character in the word is replaced by its code / the codes are stored in the order in the word B1
  3. (c)(i) 49 = 3 × 16 + 1 → 31 B1
  4. (c)(ii) 49 + 4 = 53 B1
6 Check it does the answer make sense?

'5' must have a bigger code than '1' and the digits run in order: 53 = 49 + 4 ✓. The report: “a common incorrect answer for extended ASCII was 255”.

Example 2 · Unicode characteristics and an extended ASCII table (Paper 1, 5 marks) ★ Easy
9618/13/M/J/25 Q1Paper 1 · Theory fundamentalsPart (c)5 marksFull size
(c) The student types a report on a computer. (i) The computer uses the Unicode character set. Give two characteristics of the Unicode character set. [2] (ii) Some of the school's computers use the extended ASCII character set. The table gives characters with their denary, 8-bit binary and hexadecimal numbers: ! 33 … 21; L … 01001100 4C; ü 252 11111100 …. Complete the table by filling in the missing numbers. [3]
1 Read it with me what is actually happening?

(i) wants two facts about Unicode. (ii) is a table: each row gives you one or two forms of the same code and you fill the gap.

  • characteristicsfeatures of Unicode: bits, how many characters, what it covers
  • 8-bit binarypad to 8 bits
2 What is it asking for? the target, part by part
  • (c)(i)two characteristics2
  • (c)(ii)three missing values3
3 What do we know? everything the question gives us
  • ! = 33, hex 21
  • L = 0100 1100, hex 4C
  • ü = 252 = 1111 1100
4 Plan the route work backwards from what we want
FindKey ideaAlready have itWork out firstTrap
  • (ii)missing values
    • !33 → 8-bit binary
    • Lbinary → denary
    • übinary → hex
Quick check for 33 in binary?

33 = 32 + 1 → 0010 0001, and hex 21 = 0010 0001 too ✓.

5 Now solve it have a go on paper first, then open the worked solution
  1. (i) 8 / 16 / 32 bits per character B1; represents \(2^{16}\) / \(2^{32}\) etc. characters // every language and other characters such as emojis B1
  2. (ii) ! : 33 → 0010 0001 B1
  3. L: 0100 1100 = 64 + 8 + 4 = 76 B1
  4. ü: 1111 1100 → FC B1
6 Check it does the answer make sense?

Each row now has three forms that agree: 4C = 4 × 16 + 12 = 76 ✓, FC = 252 ✓.

Example 3 · Unicode advantages and two code conversions (Paper 1, 4 marks) ★★ Medium
9618/11/M/J/25 Q3Paper 1 · Theory fundamentalsPart (b)4 marksFull size
(b) The text in the files is stored using the Unicode character set. (i) Give two advantages of using the Unicode character set instead of using the ASCII character set. [2] (ii) The Unicode character has the binary value 0010 0111 0110 1110. Convert it into denary. [1] (iii) The Unicode character has the hexadecimal value 2140. Convert it into denary. [1]
1 Read it with me what is actually happening?

16-bit codes this time. The fastest route for both conversions goes through hex place values (4096, 256, 16, 1).

  • advantages … instead of ASCIIcompare: what can Unicode do that ASCII can't
  • 16 bitsfour hex digits
2 What is it asking for? the target, part by part
  • (b)(i)two advantages2
  • (b)(ii)binary → denary1
  • (b)(iii)hex → denary1
3 What do we know? everything the question gives us
  • 0010 0111 0110 1110(ii)
  • 2140 hex(iii)
4 Plan the route work backwards from what we want
FindKey ideaAlready have itWork out firstTrap
  • (ii)denary
    • Hex first2 7 6 E
    • Place values2×4096 + 7×256 + 6×16 + 14
  • (iii)denary
    • Place values2×4096 + 1×256 + 4×16 + 0
Why go through hex for (ii)?

Adding 16 binary place values is slow and error-prone; four hex digits are quicker.

Is the answer to (ii) bigger than 8192?

Yes: the first hex digit is 2 (2 × 4096 = 8192).

5 Now solve it have a go on paper first, then open the worked solution
  1. (i) A wider range of characters can be represented B1 … so characters from more languages can be represented // and symbols such as emojis B1
  2. (ii) 0010 0111 0110 1110 = 276E hex = 2 × 4096 + 7 × 256 + 6 × 16 + 14 = 8192 + 1792 + 96 + 14 = 10 094 B1
  3. (iii) 2 × 4096 + 1 × 256 + 4 × 16 + 0 = 8192 + 256 + 64 = 8512 B1
6 Check it does the answer make sense?

Both are between 8192 (2000 hex) and 12 288 (3000 hex), as their first hex digit 2 says ✓.

Example 4 · Unicode bits, then one ASCII code in BCD and hex (Paper 1, 3 marks) ★★ Medium
9618/12/O/N/25 Q7Paper 1 · Theory fundamentalsParts (b) and (c)3 marksFull size
(b) A computer uses the Unicode character set. State the number of bits used to store one character from the Unicode character set. [1] (c) ASCII is another character set. The ASCII value for the character 'h' has the denary value 104. (i) Write the Binary Coded Decimal (BCD) value for the ASCII character 'h'. [1] (ii) Write the hexadecimal value for the ASCII character 'h'. [1]
1 Read it with me what is actually happening?

(c) mixes this page with page 1: the code 104 is just a number, so put it into BCD (digit by digit) and into hex.

  • BCD value1, 0, 4 → three nibbles
  • hexadecimal value104 = ? × 16 + ?
2 What is it asking for? the target, part by part
  • (b)bits per Unicode character1
  • (c)(i)104 in BCD1
  • (c)(ii)104 in hex1
3 What do we know? everything the question gives us
  • 'h' = 104
4 Plan the route work backwards from what we want
FindKey ideaAlready have itWork out firstTrap
  • (c)(i)BCD
    • Trap0110 1000 is plain binary, not BCD
  • (c)(ii)hex
    • ÷ 16104 = 6 × 16 + 8
How many nibbles does BCD of 104 need?

Three: 1, 0 and 4.

5 Now solve it have a go on paper first, then open the worked solution
  1. (b) 8 // 16 // 32 (also 64 was accepted) B1
  2. (c)(i) 1 → 0001, 0 → 0000, 4 → 0100: 0001 0000 0100 B1
  3. (c)(ii) 104 = 6 × 16 + 8 → 68 B1
6 Check it does the answer make sense?

Check (ii) via binary: 104 = 0110 1000 → 6, 8 ✓.

Summary

  • Character set: all the characters a computer can represent, each with a unique code.
  • Text: each character replaced by its code, codes stored in sequence.
  • ASCII 7 bits, 128 characters; extended ASCII 8 bits, 256; Unicode 16/32 bits, 65 536+ characters, all languages, emoji. ASCII is a subset of Unicode.
  • Codes are consecutive within letters and digits: count on from a given code; lower case = upper case + 32.
If you see…do this
“describe a character set”all characters it can represent + unique code each
“explain how the word … is represented”unique code per character + stored in sequence
“difference(s) between ASCII and Unicode”bits per character / number of characters / languages, each comparing both
a code for one character, asked for anothercount on (letters and digits are consecutive)
“give the code in hex / BCD / binary”it is just a number: use the page 1 conversions

Can I do this?

Anything unticked: revise that section first. All ticked: take the quiz.

Quiz

The multiple-choice and guided questions need JavaScript. The concept checks and exam practice below work without it.

Concept checks

Answer each one in your head first, then open it.

1Why must every character's code be unique?Show answer

If two characters shared a code, the computer reading the text back could not tell which one was meant.

2Why can't ASCII store a message in Urdu?Show answer

ASCII has only 128 (or 256) codes, all used for English letters, digits and symbols; there are no codes left for Urdu letters.

3A file written in extended ASCII on one computer shows wrong symbols on another. Why?Show answer

Different computers used different meanings (code pages) for codes 128-255. Unicode fixed this by giving every character one code everywhere.

4Is the character '7' stored as 0000 0111?Show answer

No: that is the number 7. The character '7' is stored as its code (55 in ASCII = 0011 0111).

Exam-style practice

New questions, not used above. Do them on paper, then mark your work against the official mark scheme.

Q19618/13/O/N/24 Q6Paper 1 · Theory fundamentalsPart (a)2 marksFull size
A computer system stores text, images and sound. (a) A character set is used to represent characters in a computer. Identify and describe one character set. [2]
Show the mark scheme
PartAnswer / workingMarksGuidance
(a)ASCII // UNICODEB1identification
ASCII: 7/8 bits per character // represents 128/256 characters // all characters from the Latin alphabet. Unicode: 8/16/32 bits per character // represents 256/65 536+ characters // all characters in all languagesB1description must match the set named
Total: 2 marks
Q29618/12/O/N/25 Q6Paper 1 · Theory fundamentalsPart (b)1 markFull size
(b) The table shows some words and corresponding denary values: Computing 55, Science 56, Computers 57, are 58, Brilliant! 59, is 60, Fun! 61, Amazing! 62. Three bytes are received: 00111000, 00111100, 00111110. Use the table to find the corresponding words. [1]
Show the mark scheme
PartAnswer / workingMarksGuidance
(b)Science, is, Amazing!B1all three in the correct order: 56, 60, 62
Total: 1 mark

Examiner tip Convert each byte to denary first, then look it up; keep the order of the bytes.

Q3Past-paper style3 marks

A text message contains 160 characters.

  1. (a)
    Calculate the size of the message in bytes if it is stored using 16-bit Unicode.
    [1]
  2. (b)
    The code for 'K' in this character set is 004B (hexadecimal). Give the code for 'M' in hexadecimal.
    [1]
  3. (c)
    State one reason for using Unicode instead of extended ASCII for text messages.
    [1]
Show the mark scheme
PartAnswer / workingMarksGuidance
(a)160 × 16 ÷ 8 = 320 bytesB1
(b)004DB1K, L, M: 4B + 2 = 4D
(c)Can represent a wider range of characters, e.g. other languages / emojisB1
Total: 3 marks

Your progress on this note is saved when JavaScript is on.