Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 Integer to Quaternary String Write the C function itoq) to covert an integer to a quaternary string. Its prototype is described in the header

image text in transcribed

image text in transcribed

2 Integer to Quaternary String Write the C function itoq) to covert an integer to a quaternary string. Its prototype is described in the header file itox.h. Write your code in the file 1tox.c. You can build from the stub itox.c from my hw3 directory. The idea behind itoq) is to convert an int variable (an int has 32 bits on our machine) directly to an ASCII string of quaternary digits, '0', ..., '3. In this assignment, we will consider only positive integers. The algorithm is as follows. 1. Divide the int by 4 2. The remainder is the first quaternary digit, to be placed in quaternaryStr [15] Use '0' to represent remainder 0, ' for remainder 1, and so on. 3. Update the int to be the quotient 4. Repeat steps 1, 2, and 3 for s1zeof (1nt) 4 times. When Step 2 is executed for the second time, the quaternary digit will go into quaternaryStr [14 when Step 2 is executed for the third time, the hex digit will go into quaternaryStr [13]; and so on. 5. Terminate quaternaryStr with \o. Note that the array quaternaryStr declared by the caller can be declared with a size sizeof (int) *4 1. sizeof ) is evaluated at compile time to be the number of bytes in a variable of a given type. For example, it is 4 bytes to an int on our machine, but it might be 8 bytes on a different machine. Thus sizeof ) allows your code to be portable

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

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

2. What are the components of IT infrastructure?

Answered: 1 week ago