Jimmy Xu Jimmy Xu - 1 year ago 71
Bash Question

How to perform bitwise operations on hexadecimal numbers in bash?

In my

script I have a string containing a hexadecimal number, e.g.
. Is it possible to treat it as a hex number and do bit shifting on it?

Answer Source

You can easily bitshift such numbers in an arithmetic context:

$ hex="0x12345678"
$ result=$((hex << 1))
$ printf "Result in hex notation: 0x%x\n" "$result"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download