The structure of ASCII
ASCII (1963, revised 1967) is a 7-bit code: 128 values, of which 33 are control characters and 95 are printable. Its layout was designed for mechanical teleprinters and bit-twiddling hardware, and the design still shows:
- Case is one bit.
Ais 0x41,ais 0x61: they differ only in bit 5 (value 32).c | 0x20lower-cases a letter,c & ~0x20upper-cases it, andc ^ 0x20toggles. - Digits are their value plus 48.
'7' - '0'is 7, and the low nibble of a digit's code is the digit itself (0x37 → 7). - Ctrl clears two bits. Ctrl-C sends 0x03 because C is 0x43 and the terminal clears bits 6 and 5 (
c & 0x1F). That is why Ctrl-D is EOT (4), Ctrl-H is backspace (8), Ctrl-I is tab (9), Ctrl-M is carriage return (13), Ctrl-[ is Escape (27) and Ctrl-@ is NUL. - DEL is 127, all seven bits set, because punching every hole in a paper tape was how you deleted a character.
Beyond 127
There is no “extended ASCII”. Bytes 128–255 meant different characters in every code page (Latin-1, Windows-1252, CP437, KOI8-R, ISO-8859-2 for Serbian Latin), which is the source of mojibake like “é” for “é”. Unicode replaced all of them; UTF-8 keeps bytes 0–127 identical to ASCII and uses 2–4 bytes above that. The Unicode inspector shows those bytes.
Line endings
Unix ends lines with LF (10); Windows with CR LF (13 10); classic Mac OS used CR alone. Teleprinters needed both: carriage return to move the head back, line feed to advance the paper. \r\n in a shell script's shebang line is still the most common cause of “bad interpreter” errors.
Questions
What is the ASCII code for A?
65 in decimal, 0x41 in hex, 0101 in octal, 01000001 in binary. Lower-case a is 97 (0x61).
What is ASCII 10 and 13?
10 is LF (line feed, \n) and 13 is CR (carriage return, \r). Unix uses LF alone; Windows uses CR LF.
Why does Ctrl-C send 3?
Terminals clear the two high bits of the letter’s code: C is 0x43 = 0100 0011, and 0x43 & 0x1F = 3 (ETX, end of text). The shell maps ETX to SIGINT.
Is 0xFF or 255 ASCII?
No. ASCII ends at 127. 128–255 depend on the code page, and in UTF-8 those byte values only occur as parts of multi-byte characters.