Convert decimal to hexadecimal in UNIX shell script Convert decimal to hexadecimal in UNIX shell script unix unix

Convert decimal to hexadecimal in UNIX shell script


Tried printf(1)?

printf "%x\n" 3422

There are probably ways of doing that with builtin functions in all shells but it would be less portable. I've not checked the POSIX sh specs to see whether it has such capabilities.


echo "obase=16; 34" | bc

If you want to filter a whole file of integers, one per line:

( echo "obase=16" ; cat file_of_integers ) | bc


Hexidecimal to decimal:

$ echo $((0xfee10000))4276158464

Decimal to hexadecimal:

$ printf '%x\n' 261a