Convert decimal to hexadecimal in UNIX shell script

后端 未结 11 825
孤城傲影
孤城傲影 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:20

    Tried printf(1)?

    printf "%x\n" 34
    22
    

    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.

提交回复
热议问题