ASCII
The ASCII character set is a standard defining, for character data, which bit-patterns represent which letters, numerals, and punctuation marks.
We have seen how letters have numerical values, like A is 65.
In memory, A is represented as 01000001.
This relationship is based on the ASCII character set.
ASCII characters use 1 byte of memory, and are numbered 0 to 127.
Practice Exercise¶
ASCII character codes use only 7 of a byte's 8 bits. The other bit was used in older data transmission protocols.
ASCII codes represent:
-
The letters of the American alphabet (both capital and small letters)
-
The ASCII character codes for the uppercase letters
A-Zstart at 65. -
The lowercase letters
a-zare also in ascending order starting at 97. -
Digit characters
-
The digit characters for
0-9are in order starting at 48. -
Punctuation
-
These codes are scattered throughout the ASCII table.
-
About 30 non-printable control codes
Drill¶
Go to http://www.asciitable.com/ and take a close look at how the letters and digits are organized in the table.
Practice Exercise¶
Control Characters¶
The first 32 ASCII characters are non-printable codes originally used to control teletypewriter machines. While some have no relevance in modern computing, many have been repurposed for programs that run in a terminal. For example, ASCII 10 is the "line feed" code that told a teletype machine to rotate its platen up one line - this is now our familiar newline character,
\n. This would normally have been followed by a "carriage return" code causing the machine's typing carriage to move all the way back to the left. On Windows systems, both characters are used to separate lines. On non-Windows systems only the\nnewline is used.In a terminal the first 26 control characters (after 0) can be typed using the Ctrl key and the corresponding letter: the 10th letter is J, so Ctrl-J types a newline. Ctrl-H types a backspace, Ctrl-G sounds a bell or beep if your terminal has sound enabled, Ctrl-I types a tab. ASCII 27 is Ctrl-[, the Esc code. ASCII 3 ("end of text") has been repurposed as Ctrl-C, "interrupt" (stop the current program in the terminal.)
Drill¶
ASCIIData/com.example.characters.drills.ASCIICharacters* In aforloop, iterate through the numbers0to127, printing each number and the character representation of that number (by casting it to achar) on a separate line.