bash - Have bc not drop the trailing zeros while converting hex to binary -


i have bash script convert hexadecimal binary 8 bits regardless of number supplied argument. example hexadecimal 00 should 00000000 not 0 or hexadecimal 01 should 00000001. script couldn't figure out how have bc this. possible or should manually?

this script:

#!/bin/bash j in $@     bin=$(echo "obase=2; ibase=16; $j" | bc )     echo $bin done 

i don't know whether bc support such behaviour replace

echo $bin 

with

printf "%08d\n" "$bin"