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).
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?