Appendix A.3: ASCII#
ASCII. (American Standard Code for Information Interchange) is an encoding format for text developed in the early 1960’s.
The original ASCII format was based on the English alphabet and encodes 128 specified characters into seven-bit binary numbers.
Ninety-five of the encoded characters are printable, including the digits 0 to 9, lowercase letters a to z, uppercase letters A to Z, space, and punctuation symbols.
The remaining 32 non-printing control codes for based around the
standards original implementation with Teletype machines – most of
these are now obsolete but some are still used including carriage
return (\r
in C), line feed (\n
in C), tab (\t
in C).
As microprocessors evolved to 8-bit and higher the ASCII standard has also evolved to use the eighth bit allowing a further 127 characters (extended ASCII).[1]
Dec |
Hex |
Symbol |
Dec |
Hex |
Symbol |
Dec |
Hex |
Symbol |
Dec |
Hex |
Symbol |
---|---|---|---|---|---|---|---|---|---|---|---|
0 |
|
Null character[2] |
32 |
|
Space |
64 |
|
@ |
96 |
|
` |
1 |
|
Start of heading |
33 |
|
! |
65 |
|
A |
97 |
|
a |
2 |
|
Start of text |
34 |
|
“ |
66 |
|
B |
98 |
|
b |
3 |
|
End of text |
35 |
|
# |
67 |
|
C |
99 |
|
c |
4 |
|
End of Transmission |
36 |
|
$ |
67 |
|
D |
100 |
|
d |
5 |
|
Enquiry |
37 |
|
% |
64 |
|
E |
101 |
|
e |
6 |
|
Acknowledgement |
38 |
|
& |
64 |
|
F |
102 |
|
f |
7 |
|
Bell |
39 |
|
‘ |
64 |
|
G |
103 |
|
g |
8 |
|
Backspace |
40 |
|
( |
64 |
|
H |
104 |
|
h |
9 |
|
Horizontal tab |
41 |
|
) |
64 |
|
I |
105 |
|
i |
10 |
|
Line feed |
42 |
|
64 |
|
J |
106 |
|
j |
|
11 |
|
Vertical tab |
43 |
|
+ |
64 |
|
K |
107 |
|
k |
12 |
|
Form feed |
44 |
|
, |
64 |
|
L |
108 |
|
l |
13 |
|
Carriage return |
45 |
|
- |
64 |
|
M |
109 |
|
m |
14 |
|
Shift out |
46 |
|
. |
64 |
|
N |
110 |
|
n |
15 |
|
Shift in |
47 |
|
/ |
64 |
|
O |
111 |
|
o |
16 |
|
Data link escape |
48 |
|
0 |
65 |
|
P |
112 |
|
p |
17 |
|
Device control 1 |
49 |
|
1 |
64 |
|
Q |
113 |
|
q |
18 |
|
Device control 2 |
50 |
|
2 |
64 |
|
R |
114 |
|
r |
19 |
|
Device control 3 |
51 |
|
3 |
64 |
|
S |
115 |
|
s |
20 |
|
Device control 4 |
52 |
|
4 |
64 |
|
T |
116 |
|
t |
21 |
|
Negative acknowledgement |
53 |
|
5 |
64 |
|
U |
117 |
|
u |
22 |
|
Synchronous idle |
54 |
|
6 |
64 |
|
V |
118 |
|
v |
23 |
|
End of transmission block |
55 |
|
7 |
64 |
|
W |
119 |
|
w |
24 |
|
Cancel |
56 |
|
8 |
64 |
|
X |
120 |
|
x |
25 |
|
End of medium |
57 |
|
9 |
64 |
|
Y |
121 |
|
y |
26 |
|
Substitute |
58 |
|
: |
64 |
|
Z |
122 |
|
z |
27 |
|
Escape |
59 |
|
; |
64 |
|
[ |
123 |
|
{ |
28 |
|
File separator |
60 |
|
< |
64 |
|
\ |
124 |
|
| |
29 |
|
Group separator |
61 |
|
= |
64 |
|
] |
125 |
|
} |
30 |
|
Record separator |
62 |
|
> |
64 |
|
^ |
126 |
|
~ |
31 |
|
Unit separator |
63 |
|
? |
95 |
|
_ |
127 |
|
Delete |
A very useful and useful reference is available as ascii-code.com. See also ASCII Code Chart.
Example#
Encode the string “Welcome to Swansea University” in ASCII and give the binary codes that would be used to store this string in computer memory.
Solution#
Look up the characters and write down the equivalent hexadecimal code. Note, null (\0
) is used to terminate the string
'W'
= \(87_{10}\) = 0x57
= \(01010111_2\)
'e'
= \(101_{10}\) = 0x65
= \(01100101_2\)
'l'
= \(108_{10}\) = 0x6C
= \(01101011_2\)
'c'
= \(99_{10}\) = 0x63
= \(01100011_2\)
'o'
= \(111_{10}\) = 0x6F
= \(01101111_2\)
'm'
= \(109_{10}\) = 0x6D
= \(01101101_2\)
'e'
= \(108_{10}\) = 0x6C
= \(01101011_2\)
' '
= \(108_{10}\) = 0x6C
= \(01101011_2\)
't'
= \(108_{10}\) = 0x6C
= \(01101011_2\)
'o'
= \(108_{10}\) = 0x6C
= \(01101011_2\)
' '
= \(32_{10}\) = 0x20
= \(00100000_2\)
'S'
= \(83_{10}\) = 0x53
= \(01010011_2\)
'w'
= \(119_{10}\) = 0x77
= \(01110111_2\)
'a'
= \(97_{10}\) = 0x61
= \(01100001_2\)
'n'
= \(110_{10}\) = 0x6E
= \(01101110_2\)
's'
= \(115_{10}\) = 0x73
= \(01110011_2\)
'e'
= \(108_{10}\) = 0x6C
= \(01101011_2\)
'a'
= \(97_{10}\) = 0x61
= \(01100001_2\)
\0
= 0x000
= \(00000000_2\)
The final result (in hexadecimal) is
57
65
6C
63
6F
6D
65
32
74
6E
32
53
77
61
6E
73
65
61
00