伙计们正在编写一个shell脚本。在这里我想将十进制数字转换为2位十六进制值,例如,如果我给9,它必须为09。 我做 for i in {0..255}; do hexa=$(echo "obase=16;$i" | bc) done
但第10个vlaues现在如何我应该这样shell脚本转换十进制到十六进制
由于转换提前返回一个数字十六进制值 !!!!
伙计们正在编写一个shell脚本。在这里我想将十进制数字转换为2位十六进制值,例如,如果我给9,它必须为09。 我做 for i in {0..255}; do hexa=$(echo "obase=16;$i" | bc) done
但第10个vlaues现在如何我应该这样shell脚本转换十进制到十六进制
由于转换提前返回一个数字十六进制值 !!!!
你可以用printf:
$ printf "%02x\n" 12
0c
见man bash
或您所选择的外壳的手册。
for i in {0..255}; do
printf "%X\n" $i
done
echo "enter any number"
read num
i=2
while [ $i -lt $num ]
do
p=`expr $num % $ i`
if [ $p -eq 0 ]
then
echo "$num is not prime number"
echo "since $num is divisible of $i"
exit
fi
i=`expr $i + 1`
echo "$num is prime number"
done
失败AKHIL的 “如果我给9它必须作为连锁行业09” – sarnold 2011-01-13 06:18:44