How to perform bitwise operations on hexadecimal numbers in bash?
In my bash script I have a string containing a hexadecimal number, e.g. hex="0x12345678" . Is it possible to treat it as a hex number and do bit shifting on it? You can easily bitshift such numbers in an arithmetic context: $ hex="0x12345678" $ result=$((hex << 1)) $ printf "Result in hex notation: 0x%x\n" "$result" 0x2468acf0 Of course you can do bitwise operations (inside an Arithmetic Expansion): $ echo "$((0x12345678 << 1))" 610839792 Or: $ echo "$(( 16#12345678 << 1 ))" 610839792 The value could be set in a variable as well: $ var=0x12345678 # or var=16#12345678 $ echo "$(( var << 1 ))"