Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program #1: Creation of an ASCII Table Write a C program that implements that ASCII table given on Slide 30 of the first slide set.

image text in transcribedimage text in transcribed

Program #1: Creation of an ASCII Table 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. Oct Dec 32 Char Oct Dec HexChar Hex 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 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 ofprintf (). 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, let's use the first algorithm: repeated divisions by 2. For an example, let's say our current decimal number is 74 (corresponding to a 'J' in the ASCII table). If we use this method, we would have 74 - 237 R 0 37- 2- 18 R 1 1829 R 0 92= 4 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 wil). 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 c Furthermore, for the purposes of this assignment, let's also display the leading 0 bit (even though it is not shown in the table). The final result would then be displayed as with a space between the first and second nibbles 0100 1010 Note that if you wish, you can place the calculation of the binary in its own function. If you do so, note that vou should never return a pointer from a function to something that wa:s declared locallv within that function. Therefore, if vou 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.) For this assignment, and until we get to C-strings (char arrays terminated by 0"), it would be okay to either (a) pass an array into the function that will be populated with the binary, (b) print the binary from its own function, or (c) print the binary from main () Deliverables Please submit your ".c" source code file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions

Question

What is a contestable market?

Answered: 1 week ago