Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION: For thispart of the lab, your job is to finish writing the functionflo

ID: 3616379 • Letter: Q

Question

QUESTION: For thispart of the lab, your job is to finish writing the functionfloat2bits in file FLOAT2BITS.c that has as input aFLOAT called fand as output a CHAR arraycalled fb containing as elements the bits off andinserted separators for the 3 components of a floatingpoint numberrepresentation in binary. For example, if f contains25.8125 then array fb should havethe below 38 characters stored from element 0 to 37.

0 | 10000011 |10011101000000000000000

Note that the suppliedfunction float2bitshas some very helpfulhints.

/*
* Showing the bit-representation of a float value
*
* Input   ... f
* Output ... Bits of f stored as 0 or 1 in chararray fb
*
* fb must be dimensioned at least 38.
*/

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void float2bits ( float f, char *fb)

{
   unsigned char *b;
   unsigned char h,b2[4];

   int i,k,index;


   b =(unsigned char*)(&f);

   printf("%c ", b[0]);
   /*
      b[0] ... b[3] now contains the bytesof the float f.
   */

   /*
      Insert the code to place the valueof the bits in array b
      in the proper location in the chararray fb using the Boolean
      operator & and a masking byte h(e.g., 00100000). Between the
      sign bit and the exponent field addthe characters " | " for a
      separator. Do the same betweenthe exponent and significand
      fields.

      Remember that thecetus computers are little endian!
   */
}

int main()
{

    float f;
    char fb[37];
    char fc;

    printf("Please Enter a ValidFloat Point Number: ");
    scanf("%f ", &f);
    printf("f = %f ", f);
    float2bits(f, fb);

}

Explanation / Answer

please rate - thanks /* * Showing the bit-representation of a float value * * Input   ... f * Output ... Bits of f stored as 0 or 1 in chararray fb * * fb must be dimensioned at least 38. */ #include #include #include #include void float2bits ( float f, char *fb ) {    unsigned char *b;    unsigned char h,b2[4];    int i,k,index;    unsigned int mask;    b =(unsigned char*)(&f);    /*       b[0] ... b[3] now contains the bytesof the float f.    */    /*       Insert the code to place the valueof the bits in array b       in the proper location in the chararray fb using the Boolean       operator & and a masking byte h(e.g., 00100000). Between the       sign bit and the exponent field addthe characters " | " for a       separator. Do the same betweenthe exponent and significand       fields.       Remember that the cetus computersare little endian!         */    //for ease switching bytes/bits to big endian    for(i=0;i