Skip to content
Advertisement

Convert Binary Strings (ASCII) to Binary File

I have several large files (3-6 Gb) of 1’s and 0’s characters in ASCII and I would like to convert it to a simply binary file. Newlines are not important and should be discarded.

test.bin below is 568 bytes, I would like the 560 bit file.

JavaScript

I’ve found several solutions going the other way, converting a binary file into ASCII but not the other way.

Ideally I’m looking for a simple linux / bash solution but I could live with a python solution. =================== Edit ==================

To make this less confusing consider converting any two ASCII characters into a binary file.

test_XY_encoded.txt

JavaScript

Where X represents the binary 0 and Y represents the binary 1.

Advertisement

Answer

How about this bash command?

JavaScript

‘tr’ will delete all newline characters, and the perl command converts to binary.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement