char a = <...>;
2130466 >> a & 1;
とは
https://twitter.com/kumagi/status/1014953960237436928
x86のシフト命令は下位5ビットしか見ない
The count operand can be an immediate value or the CL register. The count is masked to 5 bits (or 6 bits if in 64-bit mode and REX.W is used). The count range is limited to 0 to 31 (or 63 if 64-bit mode and REX.W is used).
Intel® 64 and IA-32 architectures software developer's manual volume 2B
x86アーキテクチャ以外で試す場合や未定義動作を避ける場合はビットマスクなり剰余なりが必要。
a-zA-Zを下位5ビットのみで表すとこうなる
ascii | decimal | mod 32 |
---|---|---|
A | 65 | 1 |
B | 66 | 2 |
C | 67 | 3 |
E | 69 | 5 |
I | 73 | 9 |
O | 79 | 15 |
U | 85 | 21 |
X | 88 | 24 |
Y | 89 | 25 |
Z | 90 | 26 |
a | 97 | 1 |
b | 98 | 2 |
c | 99 | 3 |
e | 101 | 5 |
i | 105 | 9 |
o | 111 | 15 |
u | 117 | 21 |
x | 120 | 24 |
y | 121 | 25 |
z | 122 | 26 |
小文字がちょうど大文字から+32の位置にあるのが美しいね
2130466 == 1 << 'A' % 32 | 1 << 'I' % 32 | 1 << 'U' % 32 | 1 << 'E' % 32 | 1 << 'O' % 32
理解はできても思いつかない