Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Integer to Hex string and Hex string to Integer (IN C only) 1 Interger to Hex String Write the C function itox) to covert an

Integer to Hex string and Hex string to Integer (IN C only)

image text in transcribed

image text in transcribedimage text in transcribed

1 Interger to Hex String Write the C function itox) to covert an integer to a hex string. Its prototype is described in the header file xbits.h. Write your code in the file xbits.c inyour hw3 directory. You can build from the stub xbits.c from my hw3 directory. The idea behind the itox function is to convert an int variable (int is 32 bits on our machine) 'F'. In this assignment, we will consider directly to an ASCII string of hex numbers, '0', '1', ..., ' only positive integers. The algorithm is as follows 1. Divide the int by 16. 2. The remainder is the first hex digit, to be placed in hexstring[7] Use '0' to represent remainder - 0, '1' for remainder- 1, 'A' for remainder - 10, 'B' for remainder 11, and so on 3. Update the int to be the quotient. 4. Repeat steps 1, 2, and 3 for sizeof (int) * 2 times When Step 2 is executed for the second time, the hex digit will go into hexstring[6]; when Step 2 is executed for the third time, the hex digit will go into hexstring[5], and so on 5. Terminate the hexstring with Note that the array hexstring declared by the caller can be declared with a size sizeof(int) * 2 + 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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions