Answered step by step
Verified Expert Solution
Question
1 Approved Answer
There is the code: void show_bytes(byte_pointer start, size_t len) { size_t i; for (i = 0; i printf( %.2x, start[i]); printf( ); } void show_int(int
There is the code:
void show_bytes(byte_pointer start, size_t len) {
size_t i;
for (i = 0; i
printf(" %.2x", start[i]);
printf(" ");
}
void show_int(int x) {
printf(" ival = %d ", x);
show_bytes((byte_pointer) &x, sizeof(int));
}
void show_float(float x) {
printf("fval = %f ", x);
show_bytes((byte_pointer) &x, sizeof(float));
}
void show_pointer(void *x) {
printf("pval = %p ", x);
show_bytes((byte_pointer) &x, sizeof(void *));
}
While answering this question, you must not change the prototype of the functions given. The reason is that these functions will be tested using a test driver built based on these function prototypes. O Your code must be readable and easy to understand. Therefore: Comment your code and write your program such that its statements are well spaced. No goto statements, please! O a. Modify the printf statement of the show_bytes (...) function such that it first prints the memory address of each byte then the content of the byte itself. Here is an example: Ox7ffe5fb887cc 0x80 where 0x7ffe5fb887cc is the memory address of a byte which contains the value 0x80. Compile and test your program. b. Looking at the output of this program, would you say that the CSIL computer you are using is a little endian or a big endian computer? Justify your answer by including some of the output of your program in your answer and pointing out the endianness. C. Modify the loop of the show_bytes (...) function such that, instead of using array notation to access each element of the array start, it uses pointer notation to access each of these elements. The output of your program should remain the same as in a. above: 0x7ffe5fb887cc 0x80 d. Write a function called show bits ( ). This function must have the following prototype: void show bits (int); This function must print the bit pattern of the parameter of type int. Compile and test your program. Here are two test cases (data and expected results) to illustrate the behaviour of this function: Test Case 1: If the parameter (int) is 12345, then show_bits( ... ) prints: 00000000000000000011000000111001 Test Case 2: If the parameter (int) is -12345, then show_bits( ... ) prints: 11111111111111111100111111000111 e. Write a function called mask_LSbits ( ... ). This function must have the following prototype: int mask LSbits ( int n); This function creates (returns) a mask with the n least significand bits set (to 1). For example, if n is 2, the function returns 3 (i.e., 0x00000003) and if n is 15, the function returns 32767 (i.e., 0x00007fff). What happens when n >= w or when n =w, your function must return a mask of all 1's. When n = w or when n =w, your function must return a mask of all 1's. When nStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started