An introduction to binary codes and characters
Introduction
Computer systems use binary. All data the computer uses must be in binary for it to understand and use it. In addition, the binary codes that one computer uses has to be the same set as the binary codes a different computer uses. The letter R, for example, must have the same binary code in all the different computers. If they were different, the computers wouldn't be able to communicate or use each other's files.
Binary codes
Every time you press a key on your keyboard, whether it is a capital letter or a small one, a number, a symbol, a space or punctuation mark, it gets converted into a byte, an 8 bit binary code. For example:
-
- the binary code for the capital K letter is 0100 1011 (If you convert this number from binary to decimal, you get 75)
- the binary code for the little letter t is 0111 0100 (If you convert this number from binary to decimal, you get 116)
- the binary code for the exclamation mark ! is 0010 0001 (If you convert this number from binary to decimal, you get 33)
So, if a piece of data is in binary then the computer can process it. When we press a key on our keyboard, the keyboard detects which key was pressed and sends the binary code for that particular key. If we wrote out a list of all the possible letters, numbers, symbols, special characters and punctuation on the keyboard and the code that was associated with each one, then we would a set of all the codes, and this is called (surprise surprise) a 'character set'.
The computer's character set
A character set is the set of symbols that we can represent on a computer system at any particular time. If you look at your keyboard, each of the possible keys you could press has its own code. If you wrote down all the possible characters you could press then you would have in front of you the character set known as ASCII.
Standard ASCII and Extended ASCII
The most important set of codes to represent all of the possible key presses on a computer keyboard is the American Standard Code for Information Interchange, or ASCII (pronounced 'ass-key'). It is the set of codes used by practically all communication devices that use the Latin alphabet (A - Z). In Standard ASCII, each character on the keyboard is represented by a 7 bit code. There are 96 displayable characters and 32 codes that are used for controlling e.g. printing. In Standard ASCII, for example, the letter 'A' is represented by the 7 bit code 1000001 (65 in decimal), the letter 'a' is 1100001 (97 in decimal), the '?' is represented by 0111111 (63 in decimal), a space is 32 in decimal and Null is decimal code 0. All of the different possible codes together make up what is known as the ASCII character set. If you are using 7 bits to represent a code, you have a total of 27, or 128 possible combinations. That means you can represent 128 different characters!
Standard ASCII uses 7 bits for each code. Programmers and computer people like to work in nice easy packets of 8 bits (called a 'byte'). That means that we have an extra, 8th bit to play with! What we could do is to use all 8 bits for a code instead of 7 bits so you would have a total of 28, or 256 different combinations in your character set. In other words, you can represent 128 more characters than in 7 bit ASCII. You can have a code for the letters that appear in other languages but not in the English alphabet or for graphics symbols, for example. All of the 8-bit codes together are known as the Extended ASCII character set. Most computers today use Extended ASCII so extra characters can be represented. ASCII isn't the only character set in use in computing but it is the most important one.
How the ASCII table is organised
Although memorising all of the ASCII codes might be a little difficult, knowing some key facts about it is useful:
-
- 0 is the ASCII code for null.
- 32 is the ASCII code for the space.
- 65 is the ASCII code for A.
- 97 is the ASCII code for a.
Generally speaking, the ASCII code table is organised like this:
-
- control codes, then
- punctuation, then
- digits, then
- capital letters, then
- small letters
Q1. How many bits are there in a byte?
Q2. How many bits are used in standard ASCII?
Q3. What is 27?
Q4. What is the biggest whole number you can represent if you have 7 bits? Explain your answer.
Q5. How many bits are used in extended ASCII?
Q6. What is 28?
Q7. What is the biggest whole number you can represent if you have 8 bits? Explain your answer.
Q8. What is the character set nearly all personal computers use?
Q9. Write down David as a set of decimal codes using the table above. Then convert each code to an 8 bit byte. For example, D would be 68 and converted to 0100 0100
Q10. Convert your own name into a set of decimal codes using the table above. Then convert each code to an 8 bit byte.
Extension tasks
a) Explain the difference between 'zero' and 'null'.
b) See if you can memorise the general organisation of the ASCII table, including where null, 0, the space, a and A start.
c) Find out what all the decimal codes from 0 - 31 in the ASCII table are to do with.