Does anyone know a faster calculation path for decimal to binary than in a loop?
I think the principle is similar like from decimal to octal, only the calculation without a loop would be longer.
Code: Select all
#dec-bin ???
z="338"
echo -e $["$z"/32]$[$["$z"/2]%2]$["$z"%2] # failed attempt
#dec-bin
z="338"
y=""
while [ $z -ne 0 ]; do
y=$[$z%2]$y
z=$[$z/2]
done
echo $y
#dec-oct
z="338"
echo -e $["$z"/64]$[$["$z"/8]%8]$["$z"%8]
#dec-oct
z="338"
y=""
while [ $z -ne 0 ]; do
y=$[$z%8]$y
z=$[$z/8]
done
echo $y