Convert decimal to hexadecimal in UNIX shell script

后端 未结 11 839
孤城傲影
孤城傲影 2020-11-29 19:08

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 represent

11条回答
  •  醉酒成梦
    2020-11-29 19:11

    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

提交回复
热议问题