How to calculate hexadecimal xor (^) from shell?
Like this:
echo $(( 0xA ^ 0xF ))
Or if you want the answer in hex:
printf '0x%X\n' $(( 0xA ^ 0xF ))
On a side note, calc(1)
does support xor
as a function:
$ calc
base(16)
0xa
xor(0x22, 0x33)
0x11
With any POSIX shell:
$ printf '%#x\n' "$((0x11 ^ 0x22))"
0x33
gdb has powerful expression calculator:
gdb -q -ex 'print/x 0xA ^ 0xF' -ex q
A shell function:
calc_gdb() { gdb -q -ex "print/x $*" -ex q;}
calc_gdb 0xA ^ 0xF
$1 = 0x5