[英]Converting decimal to hexadecimal in bash script
I want to convert a decimal number (loop index number) in a bash script to hexadecimal to be used by another command. 我想将bash脚本中的十进制数(循环索引号)转换为十六进制以供另一个命令使用。 Something like: 就像是:
for ((i=1; i<=100; i++))
do
a=convert-to-decimal($i)
echo "$a"
done
Where a should be hexadecimal with four digits and hex identifier. 其中a应为十六进制,带有四位数字和十六进制标识符。 For example if value of i is 100 , the value of a should be 0x0064 . 例如,如果i的值为100 ,则a的值应为0x0064 。 How to do it? 怎么做?
That's what you're looking for 这就是你要找的东西
for i in seq 1 100
; 因为我在seq 1 100
; do printf '%x\\n' $i done printf'%x \\ n'$ i完成了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.