Question: Hi, Im supposed to write a program in C working with bit-level operations. The two functions, that will be used are as follows: void intTWObitstr(int
Hi, Im supposed to write a program in C working with bit-level operations. The two functions, that will be used are as follows:
void intTWObitstr(int I, char *str);
int get_exp_value(float f);
The way the functions are structured in the program are as follows:
void intTWObitstr(int I, char *str)
{
/*write code here*/
}
int get_exp_value(float f)
{
unsigned f2u(float f);
unsigned int ui = f2u(f);
/*write code here*/
}
NOTE: Please leave comments explaining what each line does in the program.
With the intTWObitstr function, where I represents input and str represents output, the bit pattern of the 32 bit integer I needs to be stored in str as a 32-length string of 0s and 1s. First character in the string will be the most significant bit from I, and the last non-NULL character will be the least significant. Bit-level operations must be used to determine whether a character should be a zero or one. The only integer arithmetic that is allowed in the loop are both increment (which is ++) and decrement (which is --). The operations that are not allowed in intTWObitstr are as follows:
* function calls, macro invocations, switch statements
* subtraction, division, addition, multiplication, and modulus.
With the get_exp_value function to where f is input, you need to calculate and return the exponent value of f. It is recommended to use the provided function f2u to get the bit pattern of f. The bias of float (single precision) is 127, and any value for special values like infinity can be returned. The operations that are not allowed to be used for get_exp_value are as follows:
*Loops, macro invocations, switch statements, and function calls (except unsigned f2u (float f)).
* Division, modulus and multiplication, but subtraction is allowed.
* Relative comparison operators (<, >, <=, and >=). The only operations that are allowed are inequality (!=) and equality (==).
When the program runs, it will prompt the user to input an integer to convert to bits, and once the user makes his/her input, it will display four lines that will be printed to where the first line displays the entered integer value with its bit pattern, second line shows the hexadecimal value for the entered integer with its bit pattern, grouped by 4 bits, third line prints the floating point value (data type float), converted from the entered integer, with its bit pattern, and the last line outputs the exponent value of the floating point number.
For example, this is what the output should look like below.
Enter integer to convert to bits: 1
1 : 00000000000000000000000000000001
0x1 : 0000 0000 0000 0000 0000 0000 0000 0001
1.000000 : 00111111100000000000000000000000
Exp : 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
