Posts

Showing posts with the label Binary Files

Convert Text File Of Bits To Binary File

Answer : Adding the -r option (reverse mode) to xxd -b does not actually work as intended, because xxd simply does not support combining these two flags (it ignores -b if both are given). Instead, you have to convert the bits to hex yourself first. For example like this: ( echo 'obase=16;ibase=2'; sed -Ee 's/[01]{4}/;\0/g' instructions.txt ) | bc | xxd -r -p > instructions.bin Full explanation: The part inside the parentheses creates a bc script. It first sets the input base to binary (2) and the output base to hexadecimal (16). After that, the sed command prints the contents of instructions.txt with a semicolon between each group of 4 bits, which corresponds to 1 hex digit. The result is piped into bc . The semicolon is a command separator in bc , so all the script does is print every input integer back out (after base conversion). The output of bc is a sequence of hex digits, which can be converted to a file with the usual xxd -r -p . Output: $ hexdump -C...