Question

In: Computer Science

In a language of your own choosing, write a computer program that takes as input a...

In a language of your own choosing, write a computer program that takes as input a decimal (base 10) floating point number, and converts this number into a binary floating-point representation. The binary floating-point representation should consist of 1 bit for the sign of the significand; 8 bits for the biased exponent; and 23 bits for the significand. In addition to program source code, provide a screenshot showing the tasks identified below.

  1. Provide an output that shows your input decimal floating-point values.
  1. Demonstrate that your program works in the following input cases by showing the output in the form of 32 bits including sign bit, biased exponent, and significand:
    1. Small exponent value.
    2. Large exponent value.
    3. Negative exponent value.
    1. Negative significand.

Solutions

Expert Solution

// C program to convert a real value

// to floating point representaion

  

#include <stdio.h>

  

void printBinary(int n, int i)

{

  

    // Prints the binary representation

    // of a number n up to i-bits.

    int k;

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

  

        if ((n >> k) & 1)

            printf("1");

        else

            printf("0");

    }

}

  

typedef union {

  

    float f;

    struct

    {

  

        // Order is important.

        // Here the members of the union data structure

        // use the same memory (32 bits).

        // The ordering is taken

        // from the LSB to the MSB.

        unsigned int mantissa : 23;

        unsigned int exponent : 8;

        unsigned int sign : 1;

  

    } raw;

} myfloat;

  

// Function to convert real value

// to IEEE foating point representation

void printIEEE(myfloat var)

{

  

    // Prints the IEEE 754 representation

    // of a float value (32 bits)

  

    printf("%d | ", var.raw.sign);

    printBinary(var.raw.exponent, 8);

    printf(" | ");

    printBinary(var.raw.mantissa, 23);

    printf("\n");

}

  

// Driver Code

int main()

{

  

    // Instantiate the union

    myfloat var;

  

    // Get the real value

    var.f = -2.25;

  

    // Get the IEEE floating point representation

    printf("IEEE 754 representation of %f is : \n",

           var.f);

    printIEEE(var);

  

    return 0;

}


Related Solutions

In a language of your own choosing, write a computer program that implements the Restoring Twos...
In a language of your own choosing, write a computer program that implements the Restoring Twos Complement Division process. In addition to program source code, provide a screenshot showing the tasks below. Use 8 bits for all registers. Provide an output that shows your input decimal values. Provide an output that shows the initial values in registers A, Q, and M. Demonstrate that your program works in the following cases by showing the output in registers A and Q after...
Write an assembly language program that will print out the message of your choosing #NOTE #write...
Write an assembly language program that will print out the message of your choosing #NOTE #write in a simple way, so that i can execute it from command window using masm
IN C LANGUAGE This program takes two command line arguments: an input filename a threshold Your...
IN C LANGUAGE This program takes two command line arguments: an input filename a threshold Your program will create two files: even.txt - contains all integers from the input file that are even and greater than the threshold odd.txt - contains all integers from the input file that are odd and greater than the threshold The input file will exist and only contain a set of integers. It will always be valid data. Output whitespace will be ignored. Name the...
Problem: Write a program that takes your weight in pounds as input and then prints how...
Problem: Write a program that takes your weight in pounds as input and then prints how much you will weigh on Moon and Mars. The formula to convert weight on the Earth to weight on Moon and Mars are given below: Weight on Moon = weight on Earth * 0.165 Weight on Mars = weight on Earth * 3.711 / 9.81 You should name the program as weight_watcher.py. The output should look like as shown below:
Write an assembly language program to input a string from the user. Your program should do...
Write an assembly language program to input a string from the user. Your program should do these two things: ***** I AM POSTING THIS QUESTION FOR THE THIRD TIME NOW,I WANT IT DONE USING INCLUDE IRVINE32.INC***** 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be:...
Write a program that takes a date as input and outputs the date's season. The input...
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer:...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. The code needs to be in Java
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT