(Solved) : Hi Guys Need Help Homework Got Float Part Could Understand Pointer Part Rest Compile Run S Q44171134 . . .
Hi guys I need help with this homework: I got the float part butI could not understand the pointer part and the rest
- Compile and run the sample code that uses show_bytes (fileshow_bytes.c) on the machine to which you have access. Determinethe byte orderings used by these machines.
#include <stdio.h>
typedef unsigned char *byte_pointer;
void show_bytes(byte_pointer start, size_t len) {
int i;
for (i = 0; i < len; i++)
printf(“%.2x”, start[i]);
printf(“n”);
}
void show_int(int x) {
show_bytes((byte_pointer) &x,sizeof(int));
}
void show_float(float x) {
show_bytes((byte_pointer) &x,sizeof(float));
}
void show_pointer(void *x) {
show_bytes((byte_pointer) &x, sizeof(void*));
}
Void show_long(long x){
}
void test(int val) {
int ival = val;
//call show_int
printf(“(int) %dn”, val);
show_int(val);
//show_float
printf(“(float)%dn”,val);
show_float(val);
}
int main(int argc, char *argv[])
{
int val = 12345;
if ( argc > 1)
scanf(argv[1],“%d”, &val);
test(val);
return 0;
}
- Execute the program after filling out the codes for calling thefunctions: show_float, show_pointer in test function. Place theoutput below.
Output:
Float:
(float)12345
00e44046
- Write procedures show_short, show_long, and show_double thatprint the byte representations of C objects of types short, long,and double, respectively. Execute the program and place the outputbelow.
Output:
- Consider the following four calls to show_bytes in show_bytes.cfile:
int val = 0x87654321;
byte_pointer valp = (byte_pointer) &val;
show_bytes(valp, 1); /* A. */
show_bytes(valp, 2); /* B. */
show_bytes(valp, 3); /* C. */
show_bytes(valp, 4); /* D */
Execute the above codes in mainfunction. Then indicate the values that will be printed by eachcall on a little-endian machine and on a big-endian machine:
- Littleendian: Bigendian:
- Littleendian: Bigendian:
- Littleendian: Bigendian:
- Littleendian: Bigendian:
Expert Answer
Answer to Hi guys I need help with this homework: I got the float part but I could not understand the pointer part and the rest Co…
OR