How can hex numbers be converted to decimal numbers in a shell? This is so wrong for some reason:

echo "obase=16 ;3C9D" |bc 

    1 answer 1

     bb=0xa aa=`printf "%d" $bb` echo $aa 

    Reprinted:

     10 
    • a = 3C9D; aa = printf "%d" $a ; echo $ aa bash: printf: 3C9D: invalid number 3 - e_klimin
    • 1. it is necessary to write hexadecimal numbers with the prefix 0x 2. printf and the subsequent test should be inserted in backquotes `or $ () Everything works for me - skegg
    • one
      can be funnier echo $((0xa)) - alexlz
    • @alexlz, is also possible, but if you need to assign a value to a variable, you still need to put quotes. In addition, I read in one clever book extensive arguments about the advantages of printf over echo - skegg
    • one
      @mikillskegg a=$((0xb)); echo $a a=$((0xb)); echo $a - alexlz