Convert decimal to hexadecimal in UNIX shell script

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

    xd() {
        printf "hex> "
        while read i
        do
            printf "dec  $(( 0x${i} ))\n\nhex> "
        done
    }
    dx() {
        printf "dec> "
        while read i
        do
            printf 'hex  %x\n\ndec> ' $i
        done
    }
    

提交回复
热议问题