实现Hex和Dec转换
Submitted by on 2010, July 29, 5:37 PM. Linux
特别提示:本站正在通过Google广告盈利,你也可以!详情请看:
使用下面两个脚本即可:
1. Dec转Hex
hex()
{
typeset -i HeX
((HeX=16#0))
while [ $# != 0 ]
do
((HeX=$1))
print -n "0x${HeX#16#}"
shift
done
print -
}
2. Hex转Dec
dec()
{
((DeC=0))
while [ $# != 0 ]
do
((DeC=16#${1#0x}))
print -n "${Dec}"
shift
done
print -
}
使用下面两个脚本即可:
1. Dec转Hex
hex()
{
typeset -i HeX
((HeX=16#0))
while [ $# != 0 ]
do
((HeX=$1))
print -n "0x${HeX#16#}"
shift
done
print -
}
2. Hex转Dec
dec()
{
((DeC=0))
while [ $# != 0 ]
do
((DeC=16#${1#0x}))
print -n "${Dec}"
shift
done
print -
}
