Menu

Character Sets

Storing Text in ASCII

When a computer stores text, it saves a string of characters as a sequence of ASCII codes — one code for each character, kept in the order you typed them. Each code is held as a binary pattern, because binary is the only thing the computer can store. So a short message becomes a short list of codes, and a long message becomes a long list.

Everything you type counts

A space is a character and has its own code, and so does every punctuation mark — commas, question marks, exclamation marks. Type Go, Sam! and you have stored eight characters, not five: G, o, comma, space, S, a, m and exclamation mark. Each one needs its own code and its own storage.

CharacterWhat it isASCII code (denary)
Gletter71
oletter111
,punctuation44
(space)space32
Sletter83
aletter97
mletter109
!punctuation33

Working out the storage size

In standard ASCII every character uses 7 bits, so the size of a string in bits is the number of characters multiplied by the number of bits per character. The eight characters of Go, Sam! take 8 × 7 = 56 bits. Leave out the space and the punctuation marks and you would get 5 × 7 = 35 bits, which is too small — the codes for those marks still have to be stored somewhere.

Practise this