3 ASCII ([American](usa.md) standard code for information interchange) is a relatively simple standard for digital encoding of [text](text.md) that's one of the most basic and probably the most common format used for this purpose. For its simplicity and inability to represent characters of less common alphabets it is nowadays quite often replaced with more complex encodings such as [UTF-8](utf8.md) who are however almost always backwards compatible with ASCII (interpreting UTF-8 as ASCII will give somewhat workable results), and ASCII itself is also normally supported everywhere. ASCII is the [suckless](suckless.md)/[LRS](lrs.md)/[KISS](kiss.md) character encoding, recommended and [good enough](good_enough.md) for most programs.
5 The ASCII standard assigns a 7 [bit](bit.md) code to each basic text character which gives it a room for 128 characters -- these include lowercase and uppercase [English](english.md) alphabet, decimal digits, other symbols such as a question mark, comma or brackets, plus a few special control characters that represent instructions such as carriage return which are however often obsolete nowadays. Due to most computers working with 8 bit bytes, most platforms store ASCII text with 1 byte per character; the extra bit creates a room for **extending** ASCII by another 128 characters (or creating a variable width encoding such as [UTF-8](utf8.md)). These extensions include unofficial ones such as VISCII (ASCII with additional Vietnamese characters) and more official ones, most notably [ISO 8859](iso_8859.md): a group of standards by [ISO](iso.md) for various languages, e.g. ISO 88592-1 for western European languages, ISO 8859-5 for Cyrillic languages etc.
7 The ordering of characters has been kind of cleverly designed to make working with the encoding easier, for example digits start with 011 and the rest of the bits correspond to the digit itself (0000 is 0, 0001 is 1 etc.). Corresponding upper and lower case letters only differ in the 6th bit, so you can easily convert between upper and lower case by negating it as `letter ^ 0x20`. { I think there is a few missed opportunities though, e.g. in not putting digits right before letters. That way it would be very easy to print hexadecimal (and all bases up to a lot) simply as `putchar('0' + x)`. UPDATE: seen someone ask this on some stack exchange, the answer said ASCII preferred easy masking or something, seems like there was some reason. ~drummyfish }
9 ASCII was approved as an [ANSI](ansi.md) standard in 1963 and since then underwent many revisions every few years. The current one is summed up by the following table:
11 | dec | hex | oct | bin | other | symbol |
12 | ---- | ---- | ---- | ------- | --------- | --------------------- |
13 | 000 | 00 | 000 | 0000000 | \\000 ^@ | NUL: null |
14 | 001 | 01 | 001 | 0000001 | \\001 ^A | SOH: start of heading |
15 | 002 | 02 | 002 | 0000010 | \\002 ^B | STX: start of text |
16 | 003 | 03 | 003 | 0000011 | \\003 ^C | ETX: end of text |
17 | 004 | 04 | 004 | 0000100 | \\004 ^D | EOT: end of stream |
18 | 005 | 05 | 005 | 0000101 | \\005 ^E | ENQ: enquiry |
19 | 006 | 06 | 006 | 0000110 | \\006 ^F | ACK: acknowledge |
20 | 007 | 07 | 007 | 0000111 | \\a ^G | BEL: bell |
21 | 008 | 08 | 010 | 0001000 | \\b ^H | BS: backspace |
22 | 009 | 09 | 011 | 0001001 | \\t ^I | TAB: tab (horizontal) |
23 | 010 | 0a | 012 | 0001010 | \\n ^J | LF: new line |
24 | 011 | 0b | 013 | 0001011 | \\v ^K | VT: tab (vertical) |
25 | 012 | 0c | 014 | 0001100 | \\f ^L | FF: new page |
26 | 013 | 0d | 015 | 0001101 | \\r ^M | CR: carriage return |
27 | 014 | 0e | 016 | 0001110 | \\016 ^N | SO: shift out |
28 | 015 | 0f | 017 | 0001111 | \\017 ^O | SI: shift in |
29 | 016 | 10 | 020 | 0010000 | \\020 ^P | DLE: data link escape |
30 | 017 | 11 | 021 | 0010001 | \\021 ^Q | DC1: device control 1 |
31 | 018 | 12 | 022 | 0010010 | \\022 ^R | DC2: device control 2 |
32 | 019 | 13 | 023 | 0010011 | \\023 ^S | DC3: device control 3 |
33 | 020 | 14 | 024 | 0010100 | \\024 ^T | DC4: device control 4 |
34 | 021 | 15 | 025 | 0010101 | \\025 ^U | NAK: not acknowledge |
35 | 022 | 16 | 026 | 0010110 | \\026 ^V | SYN: sync idle |
36 | 023 | 17 | 027 | 0010111 | \\027 ^W | ETB: end of block |
37 | 024 | 18 | 030 | 0011000 | \\030 ^X | CAN: cancel |
38 | 025 | 19 | 031 | 0011001 | \\031 ^Y | EM: end of medium |
39 | 026 | 1a | 032 | 0011010 | \\032 ^Z | SUB: substitute |
40 | 027 | 1b | 033 | 0011011 | \\e ^[ | ESC: escape |
41 | 028 | 1c | 034 | 0011100 | \\034 ^\\ | FS: file separator |
42 | 029 | 1d | 035 | 0011101 | \\035 ^] | GS: group separator |
43 | 030 | 1e | 036 | 0011110 | \\036 ^^ | RS: record separator |
44 | 031 | 1f | 037 | 0011111 | \\037 ^_ | US: unit separator |
45 | 032 | 20 | 040 | 0100000 | | ` `: space |
46 | 033 | 21 | 041 | 0100001 | | `!` |
47 | 034 | 22 | 042 | 0100010 | \\" | `"` |
48 | 035 | 23 | 043 | 0100011 | | `#` |
49 | 036 | 24 | 044 | 0100100 | | `$` |
50 | 037 | 25 | 045 | 0100101 | | `%` |
51 | 038 | 26 | 046 | 0100110 | | `&` |
52 | 039 | 27 | 047 | 0100111 | \\' | `'` |
53 | 040 | 28 | 050 | 0101000 | | `(` |
54 | 041 | 29 | 051 | 0101001 | | `)` |
55 | 042 | 2a | 052 | 0101010 | | `*` |
56 | 043 | 2b | 053 | 0101011 | | `+` |
57 | 044 | 2c | 054 | 0101100 | | `,` |
58 | 045 | 2d | 055 | 0101101 | | `-` |
59 | 046 | 2e | 056 | 0101110 | | `.` |
60 | 047 | 2f | 057 | 0101111 | | `/` |
61 | 048 | 30 | 060 | 0110000 | | `0` |
62 | 049 | 31 | 061 | 0110001 | | `1` |
63 | 050 | 32 | 062 | 0110010 | | `2` |
64 | 051 | 33 | 063 | 0110011 | | `3` |
65 | 052 | 34 | 064 | 0110100 | | `4` |
66 | 053 | 35 | 065 | 0110101 | | `5` |
67 | 054 | 36 | 066 | 0110110 | | `6` |
68 | 055 | 37 | 067 | 0110111 | | `7` |
69 | 056 | 38 | 070 | 0111000 | | `8` |
70 | 057 | 39 | 071 | 0111001 | | `9` |
71 | 058 | 3a | 072 | 0111010 | | `:` |
72 | 059 | 3b | 073 | 0111011 | | `;` |
73 | 060 | 3c | 074 | 0111100 | | `<` |
74 | 061 | 3d | 075 | 0111101 | | `=` |
75 | 062 | 3e | 076 | 0111110 | | `>` |
76 | 063 | 3f | 077 | 0111111 | \\? | `?` |
77 | 064 | 40 | 100 | 1000000 | | `@` |
78 | 065 | 41 | 101 | 1000001 | | `A` |
79 | 066 | 42 | 102 | 1000010 | | `B` |
80 | 067 | 43 | 103 | 1000011 | | `C` |
81 | 068 | 44 | 104 | 1000100 | | `D` |
82 | 069 | 45 | 105 | 1000101 | | `E` |
83 | 070 | 46 | 106 | 1000110 | | `F` |
84 | 071 | 47 | 107 | 1000111 | | `G` |
85 | 072 | 48 | 110 | 1001000 | | `H` |
86 | 073 | 49 | 111 | 1001001 | | `I` |
87 | 074 | 4a | 112 | 1001010 | | `J` |
88 | 075 | 4b | 113 | 1001011 | | `K` |
89 | 076 | 4c | 114 | 1001100 | | `L` |
90 | 077 | 4d | 115 | 1001101 | | `M` |
91 | 078 | 4e | 116 | 1001110 | | `N` |
92 | 079 | 4f | 117 | 1001111 | | `O` |
93 | 080 | 50 | 120 | 1010000 | | `P` |
94 | 081 | 51 | 121 | 1010001 | | `Q` |
95 | 082 | 52 | 122 | 1010010 | | `R` |
96 | 083 | 53 | 123 | 1010011 | | `S` |
97 | 084 | 54 | 124 | 1010100 | | `T` |
98 | 085 | 55 | 125 | 1010101 | | `U` |
99 | 086 | 56 | 126 | 1010110 | | `V` |
100 | 087 | 57 | 127 | 1010111 | | `W` |
101 | 088 | 58 | 130 | 1011000 | | `X` |
102 | 089 | 59 | 131 | 1011001 | | `Y` |
103 | 090 | 5a | 132 | 1011010 | | `Z` |
104 | 091 | 5b | 133 | 1011011 | | `[` |
105 | 092 | 5c | 134 | 1011100 | \\\\ | `\` |
106 | 093 | 5d | 135 | 1011101 | | `]` |
107 | 094 | 5e | 136 | 1011110 | | `^` |
108 | 095 | 5f | 137 | 1011111 | | `_` |
109 | 096 | 60 | 140 | 1100000 | | `` ` ``: backtick |
110 | 097 | 61 | 141 | 1100001 | | `a` |
111 | 098 | 62 | 142 | 1100010 | | `b` |
112 | 099 | 63 | 143 | 1100011 | | `c` |
113 | 100 | 64 | 144 | 1100100 | | `d` |
114 | 101 | 65 | 145 | 1100101 | | `e` |
115 | 102 | 66 | 146 | 1100110 | | `f` |
116 | 103 | 67 | 147 | 1100111 | | `g` |
117 | 104 | 68 | 150 | 1101000 | | `h` |
118 | 105 | 69 | 151 | 1101001 | | `i` |
119 | 106 | 6a | 152 | 1101010 | | `j` |
120 | 107 | 6b | 153 | 1101011 | | `k` |
121 | 108 | 6c | 154 | 1101100 | | `l` |
122 | 109 | 6d | 155 | 1101101 | | `m` |
123 | 110 | 6e | 156 | 1101110 | | `n` |
124 | 111 | 6f | 157 | 1101111 | | `o` |
125 | 112 | 70 | 160 | 1110000 | | `p` |
126 | 113 | 71 | 161 | 1110001 | | `q` |
127 | 114 | 72 | 162 | 1110010 | | `r` |
128 | 115 | 73 | 163 | 1110011 | | `s` |
129 | 116 | 74 | 164 | 1110100 | | `t` |
130 | 117 | 75 | 165 | 1110101 | | `u` |
131 | 118 | 76 | 166 | 1110110 | | `v` |
132 | 119 | 77 | 167 | 1110111 | | `w` |
133 | 120 | 78 | 170 | 1111000 | | `x` |
134 | 121 | 79 | 171 | 1111001 | | `y` |
135 | 122 | 7a | 172 | 1111010 | | `z` |
136 | 123 | 7b | 173 | 1111011 | | `{` |
137 | 124 | 7c | 174 | 1111100 | | `|` |
138 | 125 | 7d | 175 | 1111101 | | `}` |
139 | 126 | 7e | 176 | 1111110 | | `~` |
140 | 127 | 7f | 177 | 1111111 | \\177 ^? | DEL |
144 - [Unicode](unicode.md)
145 - [PETSCII](petscii.md)
146 - [ATASCII](atascii.md)
147 - [ASCII art](ascii_art.md)
148 - [base64](base64.md)
149 - [Morse code](morse_code.md)