My Project
|
Driver to test functions of flt32.c (do not modify) More...
Functions | |
void | printBinaryMSB (int value, int msb) |
void | printBinary (int value) |
int | main (int argc, char *argv[]) |
This is a driver program to test the functions defined in flt32.h and implemented in flt32.c. The program takes one or more command line parameters and calls one of the methods, then prints the results. To see how to use the program, execute testFlt32
in a terminal window. This will print a usage statement defining how to run the program. The first parameter of the program is always a key defining which function to run. The options are:
A sample execution might be: testFlt32 abs -2.5
which prints
2.5
To use the bin
option do testFlt32 bin 1.5
which prints
dec: 1069547520 hex: 0x3FC00000 bin: 0011-1111-1100-0000-0000-0000-0000-0000
This is the decimal, hex and binary representation of the floating point number 1.5. You will find the bin
option very useful as you can determine what the correct representation of the answer should be. To test you program, choose values where the correct answer is easy to compute in your head. Then use the bin
option to determine what the answer looks like. Finally, run your program and if your answer differs from the answer you computed, use the bin
option to see the pattern of your answer. Then you need to read your program, perhaps add debugging output, and determine what your program is actually doing.
int main | ( | int | argc, |
char * | argv[] | ||
) |
Entry point of the program
argc | count of arguments, will always be at least 1 |
argv | array of parameters to program argv[0] is the name of the program, so additional parameters will begin at index 1. |
void printBinary | ( | int | value | ) |
Print a 32 bit binary representation of a value.
value | the value to be printed |
void printBinaryMSB | ( | int | value, |
int | msb | ||
) |
Print the binary representation of a value starting at the specified bit position. A separator is printed every 4 bits for easy reading.
value | the value to be printed |
msb | the bit position to begin printing (31 to 0) |