4 ms·
>"It becomes immediately obvious why, eg, ^[ becomes escape. Or that the alphabet is just 40h + the ordinal position of the letter (or 60h for lower-case). Or t
by bogomipz 10y ago
>"It becomes immediately obvious why, eg, ^[ becomes escape. Or that the alphabet is just 40h + the ordinal position of the letter (or 60h for lower-case). Or that we shift between upper & lower-case with a single bit."
I am not following, can you explain why ^[ becomes escape. Or that the alphabet is just 40h + the ordinal position? Can you elaborate? I feel like I am missing the elegance you are pointing out.
- nerdponx 10y agoESC is on the same row as [, just in another column. So Ctrl ends up being a modifier just like Shift, in that it changes column but not row. The 40h offset is 2 columns' worth.
- sarabob 10y agoif you press a letter and control, it generates the control character in the left-hand column. the letters in the third column are A = 1, B = 2 etc: 40h + the position in the alphabet. Awesome to see ^@ as null and laying it out this way makes it easier to see ^L (form-feed, as the article says: control-L will clear your terminal screen), ^G (bell), ^D, ^C etc etc
- kps 10y agoThis is so that control characters (and shifted characters — see https://en.wikipedia.org/wiki/Bit-paired_keyboard https://en.wikipedia.org/wiki/Bit-paired_keyboard) could be generated electromechanically. Remember a teletype of the era (e.g. Model 33) has no processing power.
- masklinn 10y agoBasically, that modifier keys are just flags/mask e.g. ESC is 00011011, [ is 01011011. CTRL just unsets the second MSB and shifts the column without changing the row. Physically it might have been as simple as a press-open switch on the original hardware, each bit would be a circuit which the key would connect, the SHIFT and CONTROL keys would force specific circuits open or closed.
- soneil 10y agoIf you look at each byte as being 2 bits of 'group' and 5 bits of 'character'; 00 11011 is Escape 10 11011 is [ So when we do ctrl+[ for escape (eg, in old ansi 'escape sequences', or in more recent discussions about the vim escape key on the 'touchbar' macbooks) - you're asking for the character 11011 ([) out of the control (00) set. Any time you see \n represented as ^M, it's the same thing - 01101 (M) in the control (00) set is Carriage Return. Likewise, when you realise that the relationship between upper-case and lower-case is just the same character from sets 10 & 11, it becomes obvious that you can, eg, translate upper case to lower case by just doing a bitwise or against 64 (0100000). And 40h & 60h .. having a nice round number for the offset mostly just means you can 'read' ascii from binary by only paying attention to the last 5 bits. A is 1 (00001), Z is 26 (11010), leaving us something we can more comfortably manipulate in our heads. I won't claim any of this is useful. But in the context of understanding why the ascii table looks the way it does, I do find four sets of 32 makes it much simpler in my head. I find it much easier to remember that A=65 (41h) and a=97 (61h) when I'm simply visualizing that A is the 1st character of the uppercase(40h) or lowercase(60h) set.
- amackera 10y agoThis single comment has cleared up so much magic voodoo. I feel like everything fell into place a little more cleanly, and that the world makes a little bit more sense. Thank you!
- FabHK 10y agoThe article linked mentions that the ctrl key (back then?) just clears the top 3 bits of the octet.
- bogomipz 10y agoAwesome, yes this makes total sense. I'm glad I asked. Cheers.
- ksrm 10y agoI can't believe I've only just realised where the Control key gets its name from. Thank you!
- olalonde 10y agoThere's a longer explanation on Wikipedia: https://en.wikipedia.org/wiki/Caret_notation https://en.wikipedia.org/wiki/Caret_notation