News for hackers. Stuff that matters.
Re:What happens when you press a key in your terminal? by gumby on Thursday July 21, 2022 @02:35AM (#32176444)
Look at the ascii chart by bit pattern and the characters will suddenly make sense. Here’s an old chart from the 60s that explains it:

https://programesecure.com/ascii-values-table-generator-in-c...

Unfortunately if you just see the character codes with the decimal, hex, and octal next to them this logic is obscured. Remember, it had to be implementable in (mechanical!) hardware.

Re:What happens when you press a key in your terminal? by zoomablemind on Thursday July 21, 2022 @03:59AM (#32176870)
> ...Look at the ascii chart by bit pattern and the characters will suddenly make sense.

Could you elaborate on what does the bit pattern reveal?

For example, I understand that Ctrl-C generates 0x30, which stands for ETX (end of transmission), but what is it there in 011?

Re:What happens when you press a key in your terminal? by jart on Thursday July 21, 2022 @04:31AM (#32177014)
I don't know if the chart helps, but

    #define CTRL(x) ((x) ^ 0100)
    // e.g. 'C' ^ 0100 is 3
    // e.g. '@' ^ 0100 is 0
    // e.g. 'M' ^ 0100 is 13 a.k.a. \r a.k.a. enter
I like this explanation better. It also explains what notation like ^C means. It's shorthand for 0100^C.
Re:What happens when you press a key in your terminal? by jagged-chisel on Thursday July 21, 2022 @09:38AM (#32179226)
Expanding your overloaded operator:

Crtl-C is shorthand for 0100 xor ‘C’

Also, the 0 prefix means this is a base-8 (octal) number

Re:What happens when you press a key in your terminal? by aap_ on Thursday July 21, 2022 @04:23AM (#32176980)
Ctrl clears the highest two bits. E.g. @ (ascii 0x40) turns into ^@/NUL (ascii 0x00). Similarly C (0x43) -> ^C/ETX (0x03).

Older terminals (like the VT05) used bit-pairing also with shift. They just flipped some bits depending on the upper two bits. Compare column 2 with 3 in the linked graphic, and 4,5 with 6,7.

Re:What happens when you press a key in your terminal? by gnubison on Thursday July 21, 2022 @01:09PM (#32181924)
Closer to toggling in the case of ^?.
Re:What happens when you press a key in your terminal? by aap_ on Thursday July 21, 2022 @04:31PM (#32184608)
good point!
Re:What happens when you press a key in your terminal? by gumby on Thursday July 21, 2022 @06:32PM (#32186055)
Just run your eye horizontally to see that toggling only a couple of bits move you between ^C, C, and c (back when ASCII was formalized few terminals supported lower case, and six bit character sets were common).
Re:What happens when you press a key in your terminal? by SheetPost on Thursday July 21, 2022 @05:17AM (#32177236)
> Here’s an old chart from the 60s that explains it

eh, the article linked does a very poor job of an explanation of ASCII

And no wonder, it's a deep subject - if you want answers the you want to watch this talk: https://m.youtube.com/watch?v=_mZBa3sqTrI

Re:What happens when you press a key in your terminal? by gumby on Thursday July 21, 2022 @10:30AM (#32179844)
That site didn’t let me link straight to the chart. I’ve seen that chart for years (decades) but that was the only one I could quickly find on the web.