Created
January 7, 2014 02:53
-
-
Save 6david9/8293983 to your computer and use it in GitHub Desktop.
Hex to decimal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# 获取第一个参数 | |
hex=$1 | |
# 如果参数长度不等于 6,退出 | |
if [ ${#hex} -lt 6 ] | |
then | |
echo "参数长度错误,$hex:${#hex}" | |
exit -1 | |
fi | |
# 将每两位赋值给一个参数 | |
h1=${hex:0:2} | |
h2=${hex:2:2} | |
h3=${hex:4:2} | |
# 将子字符串按 10 进制输出 | |
echo $((16#$h1)) | |
echo $((16#$h2)) | |
echo $((16#$h3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment