Needs to be in c++ format! Problem 4: 1)19 ten. 2)-7/6 ten. 3)0.3 ten. 4)63.50 t
ID: 3876806 • Letter: N
Question
Needs to be in c++ format!
Problem 4:
1)19 ten.
2)-7/6 ten.
3)0.3 ten.
4)63.50 ten.
Problem 6 (20 points) Write a C/C++ program to extract the sign bit, exponent field, and the fraction field of a 32-bit hexadecimal number (in the IEEE 754 standard) and then compute the corresponding floating- point in decimal using formula (-I)'g x(1+fraction×2-23)x2ep -127)(You can ignore special cases including 0). Print each field as unsigned hexadecimal (%X) and the decimal value in scientific notation ("%E"). Then apply your program on the four representations from Problem 4 above (single precision only) and include your running results. You need to attach a copy of your program or submit it electronically. Program hint: You may find the following union structure convenient. union ieee754_hex { unsigned int hex; struct unsigned int fraction:23; unsigned int exponent:8; unsigned int s:1;Explanation / Answer
#include<iostream>
union ieee754
{
unsigned int hex;
struct mem
{
unsigned int fraction:23;
unsigned int exponent:8
unsigned int sign:1;
};
};
int main()
{
int dec;
union ieee754 u1;
struct mem m1;
printf("please enter a hexadecimal no of 32 bit in hexadecimal format");
scanf("%x",&u1.hex);
printf("the fraction bit is %X decimal value of scientific notation %E",u1.m1.fraction,u1.m1.fraction);
printf("the exponent bit is %Xdecimal value of scientific notation %E",u1.m1.exponent,u1.m1.exponent);
printf("the sign bit is %X decimal value of scientific notation is %E",u1.m1.sign,u1.m1.sign);
dec=((-1)^(u1.m1.sign))*((1+u1.m1.fraction)*(2^(-23)))*((2^(u1.m1.exponent-127)));
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.