Write a program in C++ that converts decimal numbers to IEEE Standard 754 Floating Point Single Precision.
Please include code that converts to single precision and double precision as a second option.
CODE
#include <iostream>
using namespace std;
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;
} myfloat1;
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 long mantissa : 52;
unsigned int exponent : 11;
unsigned int sign : 1;
} raw;
} myfloat2;
// Function to convert real value
// to IEEE foating point representation
void printIEEE(myfloat1 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");
}
// Function to convert real value
// to IEEE foating point representation
void printIEEE(myfloat2 var)
{
// Prints the IEEE 754 representation
// of a float value (32 bits)
printf("%d | ", var.raw.sign);
printBinary(var.raw.exponent, 11);
printf(" | ");
printBinary(var.raw.mantissa, 52);
printf("\n");
}
// Driver Code
int main()
{
// Instantiate the union
myfloat1 var1;
myfloat2 var2;
printf("Enter a decimal number: ");
float num;
scanf("%f", &num);
printf("1. For single precision\n2. For double precision\nEnter your choice: ");
int choice;
scanf("%d", &choice);
if (choice == 1) {
// Get the real value
var1.f = num;
// Get the IEEE floating point representation
printf("IEEE 754 single precision representation of %f is : \n",
var1.f);
printIEEE(var1);
}
else if (choice == 2) {
// Get the real value
var2.f = num;
// Get the IEEE floating point representation
printf("IEEE 754 double precision representation of %f is : \n",
var2.f);
printIEEE(var2);
}
return 0;
}
Write a program in C++ that converts decimal numbers to IEEE Standard 754 Floating Point Single...
To write a C program (not C++) that converts numbers between Decimal and IEEE-754 format and vice versa. Inputs: Number in Decimal format (including special case of 0) Number in IEEE-754 format (including special cases) Output: Equivalent number in IEEE-754 format Equivalent number in Decimal Specification: The program converts a number based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are: Decimal to IEEE-754 conversion IEEE-754 to Decimal conversion Quit program...
1 please
IEEE-754 Floating point conversions problems (assume 32 bit machine): 1. For IEEE 754 single-precision floating point, write the hexadecimal representation for the following decimal values: a. 27.1015625 b.-1 2. For IEEE 754 single-precision floating point, what is the decimal number, whose hexadecimal representation is the following? a. 4280 0000 b. 7FE4 0000 c. 0061 0000 3. For IEEE-754 single-precision floating point practice the following problem: Suppose X and Y are representing single precision numbers as follows: X 0100...
What are the largest positive representable numbers in 32-bit
IEEE 754 single precision floating point and double precision
floating point? Show the bit encoding and the values in base 10. a)
Single Precision
b) Double Precision
link to circuit:http://i.imgur.com/7Ecb2Lw.png
Please show steps
EXERCICE4 The following real numbers are given in single precision (ieee-754 floating point) format. Negate each of them. Single Precision FP Inverse (negated) value in single precision FP Ox3FCO0000 OxAFC00000 0x43806000 0xC3906000 0x41200000 0xF1200000 0x3F7F0000 EXERCICE 5 Express the following real numbers (single precision ieee-754 floating point) in decimal notation Single Precision FP Value in base 10 0x3FC00000 0xBFC00000 0x43806000 0xC3806000 0x41200000 0xC1200000 0x3F7F0000
Starting point: 79.125 Find the: The IEEE 754 single-precision floating-point representation of the decimal value. Please write your final answer with spaces between the sign, exponent, and mantissa
Watching a YouTube tutorial on how to convert decimal to
floating point numbers (IEEE 754) and normalisation may prove to be
beneficial.
Watching a YouTube tutorial on how to convert decimal to floating point numbers (IEEE 754) may prove to be beneficial Convert the decimal number to 32 bits I Decimal number 18 to its binary equivalent I. 18 normalized in binary: 1.-2刈2n) II Biased exponent: 10 IV. Conversion to EE 754 16 I: 10, For ii please normalize the...
Convert decimal number 289.5625, to IEEE 754 single precision floating point. Please show all steps and explain what to do in each step.
This problem covers floating-point IEEE format. (a) Assuming single precision IEEE 754 format, what is the binary pattern for decimal number -6.16? (b) Assuming single precision IEEE 754 format, what decimal number is represented by this word: 0 01111100 01100000000000000000000 (Hint: remember to use the biased form of the exponent.)
(2 pts) Express the base 10 numbers 16.75 in IEEE 754 single-precision floating point format. Express your answer in hexadecimal. Hint: IEEE 754 single-precision floating-point format consists of one sign bit 8 biased exponent bits, and 23 fraction bits) Note:You should show all the steps to receive full credits) 6.7510 Type here to search
P8 (12 points): Convert the following numbers from IEEE 754 Single- Precision Floating Point format to decimal. Note that each number is given in hexadecimal. You may leave the result as a fraction. A: BF00000016 B: 4208000016 C: BD60000016