epichero22
asked on
Converting eight-bit binary to ASCII in C++
Hi,
I am writing a practice program on my computer generate all the ASCII characters in order based on their binary equivalents. So what I'd like to do is start with an eight-bit binary number, convert it to ASCII, and output it on the screen. The increment the binary number and output that and so on. I'm not really sure how to start this and was wondering if you could help.
I am writing a practice program on my computer generate all the ASCII characters in order based on their binary equivalents. So what I'd like to do is start with an eight-bit binary number, convert it to ASCII, and output it on the screen. The increment the binary number and output that and so on. I'm not really sure how to start this and was wondering if you could help.
The above output was produced using VS 2010 Express in a DOS window.
Here is the ASCII chart for what the symbols are supposed to look like:
http://www.ascii-code.com/
"The first 32 characters (i.e., 0-31) in the ASCII-table are unprintable control codes and are used to control peripherals such as printers."
Notice that the decimal number 10 has a line space after it. That is because decimal 10 corresponds to a linefeed.
The standard ASCII set are the decimal values from 32 (i.e., space) to 127. When their binary equivalent is sent to a monitor, then the monitor converts it to the corresponding symbol.
Here is the ASCII chart for what the symbols are supposed to look like:
http://www.ascii-code.com/
"The first 32 characters (i.e., 0-31) in the ASCII-table are unprintable control codes and are used to control peripherals such as printers."
Notice that the decimal number 10 has a line space after it. That is because decimal 10 corresponds to a linefeed.
The standard ASCII set are the decimal values from 32 (i.e., space) to 127. When their binary equivalent is sent to a monitor, then the monitor converts it to the corresponding symbol.
In case you are interested in how print works, and the different ways to convert a variable to something that you can (usually) see on a screen, take a look at:
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
Notice that the %d takes an integer value and prints out the "Signed decimal integer"; and that %c simply prints out the "Character". For decimal values outside the range 32 .. 127, it may be possible to set the screen to yield different characters.
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
Notice that the %d takes an integer value and prints out the "Signed decimal integer"; and that %c simply prints out the "Character". For decimal values outside the range 32 .. 127, it may be possible to set the screen to yield different characters.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Too many replies. Why not just post it all in one?
Open in new window
Open in new window