user3535581
user3535581

Reputation: 39

Convert text file containing 0 &1 to binary file

Hi I just wrote a program for Huffman Encoding in c++, where I take a text file, encode it in the form of 0's and 1's, and save that as another text file. However, this does not solve my purpose as it is taking even more space.

So I want to know how do I convert a text file containing these 0'S & 1's to a binary format.

Thank You in advance. :)

Upvotes: 1

Views: 981

Answers (1)

ZivS
ZivS

Reputation: 2124

You can loop the text, each iteration read 8 chars from the text, convert this number to a single BYTE and write this byte to a file with ios::binary

Update:This might require you to know if your machine is little/big endian, depending on how you convert to BYTE

Upvotes: 1

Related Questions