Here you can convert binary to text. The translation will convert the binary code to decimal and then use the ASCII table to represent the characters behind that decimal codes.
Below you can learn how to do the conversion yourself and even how to implement such converter in C.
Auto format the input
To generate binary code from ASCII text use the text to binary converter.
Computers represent the information, using numbers. Every symbol has a distinct numeric code. The mechanism of symbol representation is called character encoding.
To do the conversion, we need to do several tasks:
Here is an example:
010000010100001001000011 = ABC
Using the binary alphabet we can make the above conversion easier. Let's say, that for some reason you convert binary to text on paper. We can skip step 4 and directly map the binary value to its ASCII symbol. For this, we need a table to look up the mappings. We can call this table our binary alphabet.
In this mapping we will add the English letters (both capital and lowercase) and several other symbols that could be useful – space, comma, dot...
For other symbols from the binary alphabet you can use the text to binary converter.
In this implementation we will use the function from the binary to decimal conversion lesson.
The example implementation (free download: binary-to-text.zip) also has validation and formatting. We will not go into details there. Instead we will keep focus on the conversion itself.
We aim to convert up to about 500 binary digits to ASCII. 496 is the closest multiple of 8, so that is the biggest binary size that we will handle. This is enough to encode 62 ASCII symbols. The input could contain one space between the octets so we allocate 496 + 62 + 1(null terminator) = 559 bytes.
By default, scanf will scan for a string until the first whitespace. This means that if we enter the 01000001 01000010, it will read only the first octet. To avoid this, we use the special formatter [^\n]. This tells scanf to read until it reads the new line symbol (the return key).
Then we allocate the necessary memory for the result text and start the conversion:
Once we have the input in the correct format, the conversion is very simple. We take each octet, convert it to its decimal representation and save the resulting code. As we said earlier, we use the binaryToDecimal function, that we created in another lesson.
One thing that to look for, is to count the number of symbols. We need that count, so we can reset the pointer to the first symbol.
Now the binary to text conversion is finished. We can print the result and free any memory that we allocated on the heap with the malloc function above.
You can also do the reverse conversion. To see how it is done go to text to binary lesson.