A-Level Computer Science / Unit 1: Representing Information

1.1.5 Text Representation in Binary

πŸ”’ Lesson slides are available to signed-in users. Sign in

1.1.5 Text Representation in Binary

A computer stores text as numbers. A character set assigns an identifying value to each character, and an encoding converts that value into one or more bytes for storage or transmission.

This section compares ASCII, extended ASCII, Unicode, and UTF-8. It also distinguishes a character's identity from the bytes used to represent it.

By the end of this section, you should be able to:

  • explain why text requires a character coding system;
  • describe the size and purpose of standard ASCII and extended ASCII;
  • distinguish a Unicode code point from a character encoding;
  • explain why UTF-8 uses a variable number of bytes;
  • recognise UTF-8 start-byte and continuation-byte patterns;
  • compare the storage needed by different characters.

Exam focus

Use precise language: a character set assigns values to characters, while an encoding specifies how those values are stored as bytes.

From Character to Binary

Text contains letters, digits, punctuation, spacing characters, and control instructions. A computer needs an agreed mapping so that the same stored value is interpreted consistently.

Character set: a collection of characters with an assigned numeric value for each one.
Character encoding: a rule for representing those values using bytes.

A three-stage model

Stage Example Purpose
Character Ξ© The symbol a person reads.
Code point U+03A9 The Unicode identifier assigned to the character.
Encoded bytes CE A9 in UTF-8 The bytes stored or transmitted.

Common misconception

The visual shape of a character is not stored as text. Its code is stored. A font later determines how the character is drawn on screen or paper.

Standard ASCII

Standard ASCII uses 7 bits, giving 27 = 128 possible codes. It was designed mainly for basic English text, punctuation, digits, and control purposes.

When an ASCII value is stored in an 8-bit byte, the unused most significant bit is normally 0.

Character Hexadecimal code 8-bit storage
H4801001000
i6901101001
?3F00111111
Space2000100000

Worked example: storing β€œHi?”

Each character is encoded independently:

H β†’ 01001000
i β†’ 01101001
? β†’ 00111111

The complete three-character message therefore needs three bytes in ASCII.

Text digit or numeric value?

The character "5" and the numeric value 5 serve different purposes. Text "5" uses a character code; numeric 5 is stored as a number for arithmetic.

Exam tip

You normally need to know the size and purpose of ASCII, not memorise an entire code table.

Extended ASCII

Extended ASCII uses all 8 bits, allowing 28 = 256 code values. The extra values can represent additional symbols or accented letters.

Feature Standard ASCII Extended ASCII
Bits used78
Possible codes128256
Main strengthConsistent basic English setMore regional symbols and letters
Main limitationVery limited language coverageDifferent code pages may disagree

Common misconception

β€œExtended ASCII” does not refer to one single universal set of 256 characters. Different 8-bit code pages may assign different meanings to values above 127.

Unicode

Unicode provides a shared numbering system for characters used across many languages, technical fields, and symbol collections.

Code point: the numeric identifier assigned to a Unicode character, commonly written as U+ followed by hexadecimal digits.
Character Code point Description
Ξ©U+03A9Greek capital omega
ζ°΄U+6C34Chinese character meaning water
€U+20ACEuro sign
πŸ˜€U+1F600Emoji

Unicode is not the same as UTF-8

Unicode identifies characters. UTF-8 is one method for turning Unicode code points into bytes.

UTF-8

UTF-8 is a variable-length Unicode encoding. A character can use one, two, three, or four bytes. The opening bits indicate the role of each byte.

Byte count Pattern Interpretation
10xxxxxxxSingle-byte character
2110xxxxx 10xxxxxxStart byte plus one continuation byte
31110xxxx 10xxxxxx 10xxxxxxStart byte plus two continuation bytes
411110xxx 10xxxxxx 10xxxxxx 10xxxxxxStart byte plus three continuation bytes

Comparing UTF-8 byte lengths

Character Code point UTF-8 bytes Storage
HU+0048481 byte
Ξ©U+03A9CE A92 bytes
ζ°΄U+6C34E6 B0 B43 bytes
πŸ˜€U+1F600F0 9F 98 804 bytes

How to recognise a continuation byte

A UTF-8 continuation byte begins with 10. The first byte indicates how many bytes belong to the character.

Common mistake

One character does not always equal one byte. That is true for ASCII characters in UTF-8, but many other characters require multiple bytes.

Interactive: ASCII and Character Code Explorer

Type one character to inspect its denary, hexadecimal, and binary values.

Character --
Denary code --
Hexadecimal --
Binary byte --------
Type a character to begin.

Interactive: UTF-8 Byte Structure Visualiser

Select a character and follow how UTF-8 divides its stored representation into bytes.

Normal
Character A
Code point U+0041
Bytes needed 1
Press Next step to begin.

Practice and Review

Try these questions

  1. Explain why a computer needs an agreed character set.
  2. State the number of codes available in 7-bit ASCII.
  3. Compare standard ASCII with extended ASCII.
  4. Explain the difference between a Unicode code point and UTF-8 bytes.
  5. Identify the UTF-8 byte count from each prefix: 0, 110, 1110, and 11110.
  6. Explain how a decoder recognises a continuation byte.
  7. Explain why the text character "5" is not stored in the same way as numeric 5.

Final checklist

  • Use the correct number of bits for ASCII.
  • Separate character identity from byte encoding.
  • Mention variable-length storage for UTF-8.
  • Use the prefix 10 when explaining continuation bytes.