开发者

AWK, printf format specifier %x has problems with negative values

It seems AWK has problems开发者_C百科 with the unsigned hex format specifier:

echo 0x80000000 | awk '{printf("0x%08x\n", $1)}'

gives back: 0x7fffffff

Is this a known problem with awk?

Thanks!


The problem is that awk only converts input parameters to numbers automatically if they are decimal. But this should work:

echo 0x80000000 | awk '{printf("0x%08x\n", strtonum($1))}'

It's all explained in here, in the strtonum section: http://www.gnu.org/manual/gawk/html_node/String-Functions.html#String-Functions


Not seeing it here, although I wasn't able to use the hex input as you are, but converted to decimal was no problem.

$ echo 2147483648 | awk '{printf("0x%08x\n", $1)}'
0x80000000

If you care to enlighten us what platform you're on (this was GNU awk 3.1.5), we might be able to help you more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜