I'm trying to convert a hex string to binary. I'm using:
echo "ibase=16; obase=2; $line" | BC_LINE_LENGTH=9999 bc
It is truncating the leading zeroes. That is, if the hex string is 4F
, it is converted to 1001111
and if it is 0F
, it is converted to 1111
. I need it to be 01001111
and 00001111
What can I do?
bc
? There are a number of other languages you can do this at the command-line to convert a hex string to binary format with leading zeros. – Disbelieve