This tool will allow you to convert all, and display most, ASCII characters to binary and
vice versa. ASCII characters 0 through 31 may not display properly, as some of them are not intended
for visual display in a text/whatever type file.
The binary string you enter must be chunked into bytes, where one byte is
comprised of 8 bits.
How this script works is quite simple, in fact, the hardest part was making the JavaScript validation. ;-)
In order to convert the redable text, the script first loops through each character in
the string one by one. Most of the characters (at least in most Western languages) can be represented
by their ASCII decimal equivalents. Check out this ASCII conversion chart to get an idea of how characters are mapped
to decimals (the chart shows hex, octal, and HTML entity escape equivalents for convenience). In any
case, most programming languages (such as PHP) will allow you to convert the characters into decimal
form via a function, usually called ord. From there, we can use a built-in function/method
to convert the decimal to a string representation of binary. If the function doesn't ensure that the
resulting binary is 8 bits long, then we can check it's length, and prepend additional 0s, depending on
the current bit length.
This is actually easier to do. What I like to do, is strip out anything that's not a 1 or 0, using
regular expressions. After that, it's just a matter of splitting the whole binary string into chunks
of 8. At this, point, it's only a matter of looping through each chunk (should've been stored in an
array) and converting back to a decimal, and using the chr function/method to convert the
ASCII decimal into the readable, familiar text. It's that simple. For safety's sake, always escape
HTML entities when displayed on the browser to avoid any possible XSS
attacks.