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 those decimal codes.
Below you can learn how to do the conversion yourself and even how to implement such converter using the C programming language.
To generate binary code from ASCII text use the text to binary converter.
Auto format the input
represent the information, using numbers. Every symbol has a distinct
numeric code. The mechanism of symbol representation is called
One popular encoding is ASCII. We will use the ASCII table to map the binary octets to characters. Before we can do the translation, we need to convert the input from binary number system to decimal.
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.
The code is also available on Git Hub.
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 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.
Testing our program, we need to enter a binary input that will translate to visible characters, so we can verify that it is working as expected.
I used the ABC code from above 010000010100001001000011:
You can also do the reverse conversion. To see how it is done go to text to binary lesson.