追記1:2023/02/17 radare2での2進数での論理演算を追加
Pythonによる10進数での論理演算の例
AND
python
>>> 0&0
0
>>> 0&1
0
>>> 1&0
0
>>> 1&1
1
OR
python
>>> 0|0
0
>>> 0|1
1
>>> 1|0
1
>>> 1|1
1
XOR
python
>>> 0^0 # 元の数は変わらない
0
>>> 0^1 # 元の数がひっくり返る
1
>>> 1^0 # 元の数は変わらない
1
>>> 1^1 # 元の数がひっくり返る
0
radare2による2進数での論理演算の例
radare2起動
└─$ r2 -
-- It's the year of radare2 on the desktop
AND
[0x00000000]> ? 1100b & 1111b
int32 12
uint32 12
hex 0xc
octal 014
unit 12
segment 0000:000c
string "\f"
fvalue 15.0
float 0.000000f
double 0.000000
binary 0b00001100 <---ここ
ternary 0t110
OR
[0x00000000]> ? 1100b \| 1111b
int32 15
uint32 15
hex 0xf
octal 017
unit 15
segment 0000:000f
string "\x0f"
fvalue 15.0
float 0.000000f
double 0.000000
binary 0b00001111 <---ここ
ternary 0t120
XOR
[0x00000000]> ? 1100b ^ 1111b
int32 3
uint32 3
hex 0x3
octal 03
unit 3
segment 0000:0003
string "\x03"
fvalue 15.0
float 0.000000f
double 0.000000
binary 0b00000011 <---ここ
ternary 0t10
おまけ
「~」でgrepして結果の行のみ表示できる
[0x00000000]> ? 1100b & 1111b ~binary
binary 0b00001100
[0x00000000]> ? 1100b \| 1111b ~binary
binary 0b00001111
[0x00000000]> ? 1100b ^ 1111b ~binary
binary 0b00000011