全部博文(372)
2012年(372)
分类: 云计算
2012-02-25 12:29:29
from:http://blog.chinaunix.net/uid-10540984-id-2889218.html
十六进制转十进制:
如果有些字段里包含空格啊,其他一些非数字字符等,可以用它来去掉。
——————————————————————————————————————————————
注:
1、再举两个sprintf与十六进制和十进制相互转换的例子:
june@~ 02:46:13>
echo "134224939 134225061 134225342 134225407 134225494 134225539 134225542 134225545 134225548 134225596"|awk -vOFS="," 'NF+=0{for(i=1;i<=NF;i++){$i=sprintf("%x",$i)}print}'
8001c2b,8001ca5,8001dbe,8001dff,8001e56,8001e83,8001e86,8001e89,8001e8c,8001ebc
june@~ 02:52:12>
june@~ 02:52:12>
echo "8001ca5,8001dbe,8001e83,8001e86,8001e89,8001e8c,8001ebc,8001c2b,8001e56,8001dff"|awk -vFS="," -vOFS="," 'NF+=0{for(i=1;i<=NF;i++){$i=sprintf( "%s",strtonum("0x"$i))};print}'
134225061,134225342,134225539,134225542,134225545,134225548,134225596,134224939,134225494,134225407
june@~ 02:52:26>
2、python中有类似的函数做转换:
>>> print hex(134225061)
0x8001ca5
>>> print int(0x8001ca5)
134225061
>>>