Algorithms and Programming Assignment 2 (Bitwise operators and Floating Point representation) (Due on Monday 18th September 2017) This assignment is about understanding the IEEE FP representation discussed in class, and about using bitwise operators to manipulate this representation. Recall that the FP representation is 32 bits wide. Assuming that an unsigned int is also 32 bits wide on your machine, we will represent a float as an unsigned int whose bit pattern mirrors the way the float is represented on the computer. You need to implement the following steps: (a) Reading a bit pattern from the user: The code below declares "x" as an unsigned int, and takes input from the user in *hexadecimal* (hex) form. Hex is nothing but base-16, and uses the digits 0, 1, ..., 9, A, B, C, D, E, F. Thus "A" stands for the "digit" 10, and "F" stands for the "digit" 15. If the user inputs "FF000000", the bit pattern stored in x will be "1111 1111 0000 0000 0000 0000 0000 0000" (spaces added for clarity). unsigned int x; scanf("%x", &x); This unsigned int can be "interpreted" as a float. (b) Write a function "float_val" with the declaration: float float_val(unsigned int x); This function returns a float whose value is the value of the float represented by x. Thus if x contains the (hex) pattern "40000000", then the function should return a float whose value is 2.0. (c) This part is *optional*: Try it only if you like. Write a function "float_add" with the declaration: unsigned int float_add(unsigned int x, unsigned int y); which given (the unsigned int representations of) two floats, returns an unsigned int representing the sum of the floats represented by x and y. The following utility functions may be helpful to you, so implement each of them first: 1. A function "float_sign" with type int float_sign(unsigned int x) which takes an unsigned int representing a float, and returns 1 or -1 depending on whether the sign bit of the float is 0 or 1. 2. A function "float_exp" with type int float_exp(unsigned int x); that returns the value represented by the exponent bits of the given float. For example, if x contains the pattern hex "40000000", the value returned by the function should be 1. 3. A function "float_signif" with type float float_signif(unsigned int x); that returns the value of the significand of x, as a float. Thus if x is "40000000" the function should return the float value 1.0 The following utility functions may be useful in debugging your program: // print the bit pattern of an unsigned int x void print_unsigned(unsigned int x) { unsigned int i, mask; mask = 1 << 31; for(i=0; i < 32; i++) { if(x & mask) printf("1"); else printf("0"); mask = mask >> 1; } printf("\n"); } // print the float value represented by an unsigned int void print_float_val(unsigned int *p) { float *fp; fp = (float *) p; printf("%12.12f\n", *fp); } You may assume that all floats are normalized (i.e. your program does not have to work for de-normalized floats).