Convert decimal to hexadecimal in UNIX shell script

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

    In zsh you can do this sort of thing:

    % typeset -i 16 y
    % print $(( [#8] x = 32, y = 32 ))
    8#40
    % print $x $y
    8#40 16#20
    % setopt c_bases
    % print $y
    0x20
    

    Example taken from zsh docs page about Arithmetic Evaluation.

    I believe Bash has similar capabilities.

提交回复
热议问题