Skip to content

Instantly share code, notes, and snippets.

@drj11
Last active October 23, 2022 03:35
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drj11/b0131aa121f3e6fb07fa06fc12c42452 to your computer and use it in GitHub Desktop.
Save drj11/b0131aa121f3e6fb07fa06fc12c42452 to your computer and use it in GitHub Desktop.
How to memorise ASCII

How to memorise ASCII

You don't need to memorise ASCII as there is a handy chart available by typing man ascii in a Terminal. However, you may find it useful to remember some fun facts about ASCII.

Blocks of 32 are useful. 32 is 2⁵ (2 raised to the power 5) and a block of 32 is enough to represent all 26 common english letters plus some extra stuff.

ASCII is a coding for the first 128 numbers. 0 to 127. For various arcane reasons 127 is essentially unused [1].

The best block of 32 starts at 64 (which is 2*32): it contains the capital letters.

  • A is 64 + 1
  • B is 64 + 2
  • C is 64 + 3 ... and so on

@ is the "zeroth" letter and so starts the capital letter block at 64.

Lower case letters are in the next block: 97 (96 + 1) is a, 98 is b, and so on.

The space character « » is the best (most common), and it starts the block beginning at 32. So space is 32. The next two characters after space are «!» (33) and «"» (34), and are found (on a UK keyboard) as Shift-1 and Shift-2.

Next are «#», «$», and «%», and these are often found on keyboard on Shift-3, Shift-4, and Shift-5. This correspondence is tempting, but ultimately frustrating. Only the JIS keyboard has «"» on Shift-2 and «#» on Shift-3. The idea of having the shifted number keys corresponding to a small block of ASCII is called a bit-paired keyboard; the flame of this idea briefly flared with the popularity of the Teletype Model 33 and has now happily died a death. Typewriters, and typists, have been around far longer than some crummy electronic design that saves 2¢ per keyboard.

Following are some parentheses and punctuation and stuff until we get to code 48. 48 is a little bit magical because it's 3×16 or 1.5×32 so it's exactly halfway along this block. Code 48 is the character «0». There is the possibility for some confusion here, the character «0» is the character with a printed representation that is the numeral zero. Its code point is 48. It's not code point 0 (which I will get to soon).

Like the way the letters all follow in sequence, so do the numbers:

  • «0» code 48
  • «1» code 49
  • «2» code 50 and so on up to «9» which is code 57.

Note that in ASCII the numbers 0 to 9 come in that order; but on the keyboard you get 1 to 9 followed by 0. Whevs.

The fact that the numbers start at «0» allows for some convenient calculations. In ASCII the code for number N is 48 + N as long as 0 ≤ N ≤ 9

@@@

Footnotes

[1] 127 is DEL. On ancient terminal hardware you could send it by shorting the lines together with a metal key or pressing the DEL button.

@chetan2298
Copy link

thnx

@skyline180
Copy link

tnx

@pwnwriter
Copy link

nice !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment