Let us say there is a variable in bash script with value \"001\" how can i write this binary data into a file as bits (as \"001\" not \"1\") echo writes it as string but i w
A couple of more general functions to output integers to a file:
le16 () { # little endian 16 bit; 1st param: integer to 2nd param: file
v=`awk -v n=$1 'BEGIN{printf "%04X", n;}'`
echo -n -e "\\x${v:2:2}\\x${v:0:2}" >> $2
}
le32 () { # 32 bit version
v=`awk -v n=$1 'BEGIN{printf "%08X", n;}'`
echo -n -e "\\x${v:6:2}\\x${v:4:2}\\x${v:2:2}\\x${v:0:2}" >> $2
}