Home > database >  Converting HEX to DEC is out of range by using `mawk`
Converting HEX to DEC is out of range by using `mawk`

Time:01-05

When the hex number is relative small, I can use echo 0xFF| mawk '{ printf "%d\n", $1}' to convert hex to dec.

When then hex number is huge, mawk does not work any more, say echo 0x8110D248 | mawk '{ printf "%d\n", $1}' outputs 2147483647(which is equivalent to 0x7FFFFFFF).

CodePudding user response:

If all you need is converting Hex to Decimal, I wonder why you are using mawk. Can't you do something like

 echo 'ibase=16;8110D248' |bc

(this outputs 2165363272).

CodePudding user response:

bash can also do this (and zsh and pdksh):

echo $(( 0x8110D248 ))

Output:

2165363272
  •  Tags:  
  • Related