Given a positive decimal number, we can convert the equivalent numbers in binary; in octal and in hexadecimal. Due to the hexadecimal numbers, it is better to use character arrays to store the various conversions. We propose the following structure to store the information of a number:

struct No
{
int decimal;
char *binary;
char *octal;
` char *hexadecimal;
};

Working on a computer system, the compiler uses a fixed size to represent an integer of various formats. For example, our system uses 4 bytes to represent an integer in binary.

For the ease of this lab exercise, we assume that the compiler use 3 bytes (24 bits) to represent a positive number. Therefore, it can represent 24 / 3 = 8 octal digits and 24 / 4 = 6 hexadecimal digits.

In this lab exercise, you first construct an array of No with size randomly generated in your program, and initialize the respective char * to 0 and display the following table: see image.

You then convert each of the decimal numbers to various formats and display the following table: see image.

All storages used in your program should be dynamically created and all access to the array elements should be via the pointers and their arithmetic. In the whole design, you should not use the notation x [ i ] or *( x + i) to access to the ith element of x.

Since all the storages are dynamically created, when you exit from the program, you should help the compiler to do some garbage collections. For example, the following table should be displayed: see image.

A few important functions to be designed and use them in your program:

// This function returns the corresponding char value of an integer digit, for
// example, give any integer from 0 to 15, its returns a character from ‘0’
// to ‘9’ or from ‘A’ to ‘F’
char mapping (int);
// This function initialize all character to ‘0’
void initialize (char *, int);
// This function construct the array of No and initialize the binary, octal and
// hexadecimal numbers to 0 and the decimal numbers are randomly
// generated
void constructArray (No*, int);
// This function performs all conversions stored in the array
void processArray (No*, int);
// This function prints out the array, a tabular form as shown in this lab
void printArray (No*, int);
// This function performs the conversion of a positive integer
// with certain base and with certain size (i.e. no of bits) and
// stores the results in the character array
void convert (char*, int, int, int);
// This function performs the garbage collections.
void garbageCollection (No *, int);

Additional functions are allowed to achieve your objectives.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.