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

C program Make sure it runs please Imagine a system where the Sign, Exponent and

ID: 3886122 • Letter: C

Question

C program Make sure it runs please

Imagine a system where the Sign, Exponent and Fraction bits are 1, 5, and 10 bits in size respectively (in total 16 bits). Write down the bits representation for the number 6.5 used in IEEE Floating-point Representation (Normalized value). What would the value of the representation in short int data type. What is the floating point equivalent for the following bits representation in Normalized form. 1100000001001010 Hand simulation is needed to verify your result. (Bonus Points) According to you, what is the maximum and minimum floating point value can be represented using this 16 bits representation. Please prove your claim.

Explanation / Answer

/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
/* prints a lot of information about floating-point numbers */


#include <stdio.h>

#include <math.h>

#include <values.h>

const int EndianTest = 0x04030201;


#define LITTLE_ENDIAN() (*((const char *) &EndianTest) == 0x01)


/* extract nth LSB from object stored in lvalue x */

#define GET_BIT(x, n) ((((const char *) &x)[LITTLE_ENDIAN() ? (n) / CHARBITS : sizeof(x) - (n) / CHARBITS - 1] >> ((n) % CHARBITS)) & 0x01)

#define PUT_BIT(x, n) (putchar(GET_BIT((x), (n)) ? '1' : '0'))

void print_float_bits(float f)

{

    int i;


    i = FLOATBITS - 1;

    PUT_BIT(f, i);

   putchar(' ');

for(i--; i >= 23; i--)
{

       PUT_BIT(f, i);

    }

    putchar(' ');

   for(; i >= 0; i--)
{

        PUT_BIT(f, i);

   }

}


int
main(int argc, char **argv)

{

    float f;

    printf("Enter Floating number: ");
    while(scanf("%f", &f) == 1)
{

        printf("%10g = %24.17g = ", f, f);

        print_float_bits(f);

        putchar(' ');

    }


    return 0;

}