Computer science: bits, bytes, and ASCII
Tutoring computer science, a computer’s internal representation of characters is of interest. The tutor introduces the topic.
Most people probably have heard that computers “just think in 1s and 0s”. Yet, even a programmer rarely communicates with the computer in such a way. How, then, does a computer decode the text it gets fed into 0s and 1s?
The ASCII code (see the chart here) is what the computers I know of use. It’s a system that connects each character with a unique code number. For instance: looking at the chart, the character % is number 37.
Notice that the chart also gives the number 37 as 00100101, which it refers to as BIN (binary) form. Binary form means 0s and 1s. Each digit refers to a power of 2, starting with 20 at the right. 00100101 means
0x27 + 0x26 + 1×25 + 0x24 + 0x23 + 1×22 + 0x21 + 1×20
Each 0 or 1 in the binary number is a bit; the eight, together, comprise a byte. Therefore, you could also say that % is 00100101 in byte form.
00000000 equals 0; 11111111 equals 255. Therefore, there are 256 characters in the fundamental ASCII chart.
You will notice there is also a HEX column in the ASCII chart. For more about hex numbers, check out my post here.
Normally, of course, the computer converts the characters back and forth to ASCII codes without the user needing to know. However, functions exist in Perl and other programming languages that tell the user the ASCII code of a given character. The application of such functions – as well as why a programmer might need to consider the ASCII representations of characters a program receives – will be covered in future posts:)
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.