Skip to content

Instantly share code, notes, and snippets.

@6david9
Created January 7, 2014 02:53
Show Gist options
  • Save 6david9/8293983 to your computer and use it in GitHub Desktop.
Save 6david9/8293983 to your computer and use it in GitHub Desktop.
Hex to decimal
#! /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