Hexadecimal To Decimal in Shell Script

前端 未结 8 2255
北恋
北恋 2020-11-29 15:34

Can someone help me to convert a hexadecimal number to decimal number in a shell script?

E.g., I want to convert the hexadecimal number bfca3000 to deci

8条回答
  •  一向
    一向 (楼主)
    2020-11-29 16:04

    Dealing with a very lightweight embedded version of busybox on Linux means many of the traditional commands are not available (bc, printf, dc, perl, python)

    echo $((0x2f))
    47
    
    hexNum=2f
    echo $((0x${hexNum}))
    47
    

    Credit to Peter Leung for this solution.

提交回复
热议问题