ASCII (the American Standard Code for Information Interchange) is a character set that uses numbers 32 to 127 to represent a set of the main characters used in English language text. These are:
ASCII was first developed in the 1960s, but relatively few people used it at the time. An alternative scheme, called EBCDIC, was more popular.
The first IBM PCs, created in the early 1980s, used ASCII, and its popularity grew from that.
Here is a table of the 128 ACSII characters. The table shows the decimal (denary) value and the hexadecimal value for each character. For example character A has decimal value 65, which is equivalent to 0x41 in hexadecimal.
The first 32 characters in the table (NUL through to US) are called control characters. Character 127 (DEL) is also a control character. You might recognise CR (carriage return) and LF (line feed), which are used to mark the end of each line in a text file, and the TAB character which is used to align text. Most of the other control characters are no longer really used very often.
Characters 32 to 126 are used for printable characters:
You can convert a digit to an ASCII code by adding 0x30 to its value. Eg number '4' has ASCII code 0x34.
You can convert an upper case letter to lower case by adding 0x20 to its value. Eg 'Q' has code 0x51, 'q' has code 0x71.
Converting a text string to ASCII values is a simple matter of looking up each character in the table. For example, to convert "Hello" to ASCII, do the following:
Take care to look up the upper or lower case letter correctly. You should find that the ASCII values for the string "Hello" are:
[72, 115, 108, 108, 111]
Converting ASCII codes back to a text string is just as easy - look up the letter corresponding to each number. For example, to convert:
[119, 111, 114, 108, 100]
Do the following
You will find the ASCII codes represent the string "world".
Most programming languages allow you to convert between ASCII values and text characters. For example in Python 3 you can use the chr()
function to convert a value to text. For example, this code prints B (the character with ASCII value 66):
c = chr(66) print(c)
This code prints 69 (the ASCII value of character 'D'):
c = ord('D') print(c)
Most languages have similar functions.
Copyright (c) Axlesoft Ltd 2021