I am trying to convert a sequence of bytes from hex to bin using bash. but I keep getting (seemingly random) "(standard_in) 1: syntax error" answers from the following code:
for j in c4 97 91 8c 85 87 c4 90 8c 8d 9a 83 81 do BIN=$(echo "obase=2; ibase=16; $j" | bc ) echo $BIN done
I did a similar thing with dec bin, which works fine:
for i in {0..120} do KEYBIN=$(echo "obase=2; ibase=10; $i" | bc) echo $KEYBIN done
Does anyone have an idea why it works with decimal, but not with hex? In my opinion, the syntax is almost the same (unless I miss something really hard.)
bash binary hex bc
fragman
source share