In a UNIX shell script, what can I use to convert decimal numbers into hexadecimal? I thought od would do the trick, but it's not realizing I'm feeding it ASCII representations of numbers.
printf? Gross! Using it for now, but what else is available?
In
zsh
you can do this sort of thing:Example taken from
zsh
docs page about Arithmetic Evaluation.I believe Bash has similar capabilities.
Try:
In my case, I stumbled upon one issue with using printf solution:
$ printf "%x" 008 bash: printf: 008: invalid octal number
The easiest way was to use solution with bc, suggested in post higher:
$ bc <<< "obase=16; 008" 8
Sorry my fault, try this...
Example: