Question: First, your program should print out either byte order: big-endian or byte order: little-endian depending on the characteristics of the machine your code is running
First, your program should print out either "byte order: big-endian" or "byte order: little-endian" depending on the characteristics of the machine your code is running on. Your program should figure this out at run time, not at compile time. Then your code should accept user input in the form of 8 hexadecimal digits. Your code will interpret those 8 digits as an IEEE 754 32-bit floating point number and will print out information about that number. Do not worry about bad input. My test script does not do this. Use scanf to get the user input. Your code should accept input with or without "0x" in front of it (scanf does this). For each number, your code should print out:
* the sign bit * the exponent bits, expressed as a decimal number
* the fraction bits, expressed as an 8 digit hexadecimal number
Here is what your code should print out for the various types of floating point
number:
* normalized
the word "normalized" and the true exponent
(i.e. the power to which 2 will be raised in computing the numerical
value of the floating point number)
* denormalized
the word "denormalized" and the true exponent
* infinity
"+infinity" or "-infinity"
* zero
"+zero" or "-zero"
* NaN
"SNaN" or "QNaN"
Your program's output should be formatted exactly as shown in asgmt01p.output.txt (including uppercase vs. lowercase). Use %X for formatting hex output, NOT %x. Your program should exit when user input that results in a zero value is entered, after printing the information for that zero input.
******instrs.txt******
// do not change this code except in the following ways:
// * write code for the following functions:
// * bigOrSmallEndian()
// * getNextHexInt()
// * printNumberData()
// * change studentName by changing "I. Forgot" to your actual name
#include
#include
#include
static char *studentName = "I. Forgot";
// report whether machine is big or small endian
void bigOrSmallEndian()
{
}
// get next int (entered in hex) using scanf()
// returns true (success) or false (failure)
// if call succeeded, return int value via iPtr
bool getNextHexInt(unsigned int *iPtr)
{
// replace this code with the call to scanf()
*iPtr = 0;
return true;
}
// print requested data for the given number
void printNumberData(int i)
{
}
// do not change this function in any way
int main(int argc, char **argv)
{
unsigned int i; // number currently being analyzed
bool validInput; // was user input valid?
printf("CS201 - A01p - %s ", studentName);
bigOrSmallEndian();
for (;;) {
if (argc == 1) // allow grading script to control ...
printf("> "); // ... whether prompt character is printed
validInput = getNextHexInt(&i);
printf("0x%08X ", i);
if (! validInput) { // encountered bad input
printf("bad input ");
while (getchar() != ' ') ; // flush bad line from input buffer
continue;
}
printNumberData(i);
if (i == 0) {
printf("bye... ");
break;
}
}
printf(" ");
return 0;
}
*******output.txt*******
byte order: little-endian
> FFFFFFFF
0xFFFFFFFF
signBit 1, expBits 255, fractBits 0x007FFFFF
QNaN
> 3
0x00000003
signBit 0, expBits 0, fractBits 0x00000003
denormalized: exp = -126
> DEADBEEF
0xDEADBEEF
signBit 1, expBits 189, fractBits 0x002DBEEF
normalized: exp = 62
> deadbeef
0xDEADBEEF
signBit 1, expBits 189, fractBits 0x002DBEEF
normalized: exp = 62
> 0
0x00000000
signBit 0, expBits 0, fractBits 0x00000000
+zero
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
