Question: I need help with my C program, please make it as simple as possible. I need to print the ASCII table in Two columns; first

I need help with my C program, please make it as simple as possible. I need to print the ASCII table in Two columns; first column will have numbers 32 through 79 and the second column next to it will have 80 through 126. Here's the code's guidelines

Write a C program that implements that ASCII table given on Slide 30 of the first slide set. That ASCII table will be reproduced below for reference.

Your program should first print out the column headings. It should then print out the binary, octal, decimal, hexadecimal and character versions of the ASCII characters from 32 to 126 (decimal), as indicated in the table. Two vertical columns should be sufficient.

Bin Oct Dec Hex Char Bin Oct Dec Hex Char

32 33

Note that the columns should run top to bottom (instead of left to right). The range between 32 and 126 has an odd number of entries. Therefore, the left hand column will have one more entry in it than the right hand column.

As we will see shortly, the decimal, octal, and hexadecimal versions of these numbers can be easily displayed using the built-in conversion codes of printf(). The binary versions, however, are more difficult. Two algorithms for converting a decimal number to binary are (1) repeatedly divide the decimal number and its quotients by 2 and collect the remainders (the last remainder collected will be the most significant digit of the result), (2) create the hexadecimal equivalent of the original decimal number and use that hexadecimal intermediate to create the binary. The latter technique depends on the fact that the 16 hexadecimal digits (ranging from 0 to F) exactly correspond to the 16 numbers that can be created out of four bits (ranging from

0000 to 1111). The four bit binary patterns can be created from the hexadecimal digits and concatenated to produce the final result.

For this assignment, lets use the first algorithm: repeated divisions by 2. For an example, lets say our current decimal number is 74 (corresponding to a J in the ASCII table). If we use this method, we would have:

74 2 = 37 2 = 18 2 =

9 2= 4 2= 2 2= 1 2=

37 R 0 18 R 1 9 R0 4 R1 2 R0 1 R0 0 R1

After each division we capture the remainder and then divide the quotient from the previous division by 2. The process stops when the quotient becomes 0 (which it always will). The remainders are then displayed in reverse order (i.e., the last remainder collected is the most significant digit of the result) to produce the final answer: 1001010. Note that these digits should be printed out as they are in the chart, with a space between the first and second nibbles. Furthermore, for the purposes of this assignment, lets also display the leading 0 bit (even though it is not shown in the table). The final result would then be displayed as:

0100 1010

The calculation of the binary should be placed in its own function, which ever method you use.

Note that you should never return a pointer from a function to something that was declared locally within that function. Therefore, if you intend to return any kind of an array from a function, it must be passed into the function as an argument. (Alternatively, you could dynamically allocate the array. But we will discuss that issue later in the course.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!