Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include using namespace std; /*we use union and structure for IEEE 754 REPRESENTATION*/ typedef union { float f; struct { unsigned int mantissa
#include
#include
#include
using namespace std;
/*we use union and structure for IEEE 754 REPRESENTATION*/
typedef union
{
float f;
struct
{
unsigned int mantissa : 23;
unsigned int exponent : 8;
unsigned int sign : 1;
} raw;
} myfloat;
/*for converting float to binary*/
void floattobinary(float f)
{
int bit=0;
int *b = reinterpret_cast(&f);
cout>31)&1)
for (int k = 30; k >=23; k--)
{
bit = ((*b >> k)&1);
cout
}
cout
for (int k = 30; k >=23; k--)
{
bit = ((*b >> k)&1);
cout
}
}
/*for converting into base 10*/
int base10(int n,int i)
{
long int x=pow(2,i-1);
long int sum=0;
for (int k = i - 1; k >= 0; k--) {
if ((n >> k) & 1)
sum+=x;
x/=2;
}
return sum;
}
/*for convert into hexadecimal from base 10*/
int hexadecimal(int x,int z)
{
int n=base10(x,z);
char hexaDeciNum[100];
int i = 0;
while(n!=0)
{
int temp = 0;
temp = n % 16;
if(temp
{
hexaDeciNum[i] = temp + 48;
i++;
}
else
{
hexaDeciNum[i] = temp + 55;
i++;
}
n = n/16;
}
for(int j=i-1; j>=0; j--)
cout
}
/*for printing binary*/
void printBinary(int n, int i)
{
int k;
for (k = i - 1; k >= 0; k--) {
if ((n >> k) & 1)
printf("1");
else
printf("0");
}
}
/*for printing in IEEE 754 representation*/
void printIEEE(myfloat var)
{
printf("%d | ", var.raw.sign);
printBinary(var.raw.exponent, 8);
printf(" | ");
printBinary(var.raw.mantissa, 23);
printf(" ");
}
int main()
{
myfloat var;
float x,n;
cout
cin>>x;
var.f=x;
cout
cout
cout
cout
cout
cout
cout
cout
cout
int ch,y,l;
int binaryNum[8]={0};
cin>>ch;
switch(ch)
{
case 1: if(var.raw.sign==1)
cout
else
cout
break;
case 2: y=(int)x;
cout
cout
l = 0;
y=abs(y);
while (y > 0) {
binaryNum[l] = y % 2;
y = y / 2;
l++;
}
for (int j = 7; j >= 0; j--)
cout
cout
break;
case 3:
x=abs(x);
n=x-(int)x;
cout
cout
while((int)n
{
cout
n=n*2;
}
cout
break;
case 4: cout
cout
floattobinary(x);
cout
break;
case 5: cout
printBinary(var.raw.mantissa, 23);
cout
break;
case 6: cout
cout
printBinary(var.raw.exponent, 8);
cout
break;
case 7: cout
printIEEE(var);
cout
break;
case 8: cout
hexadecimal(var.raw.exponent, 8);
cout
hexadecimal(var.raw.mantissa, 23);
cout
break;
default : cout
PHASE \#1 - DESCRIPTION: Develop a plan to design and finally implement a set of functions using C++ that the IEEE standard. Phase 1 will include the literature write up, description of the and a complete description of the functions plan: 1. Functions type void, or any data returning function 2. Type of data passed in to the functions (function parameters or arguments 3. Type of function parameters (value or reference). 4. Global variables if needed. 5. IEEE 754 double precision layout and its individual parts (sign, exponent, details. 6. The hexadecimal layout. 7. Hand work out two or three example from A to Z based on your team size. 8. Use your and your partner SIS ID numbers as examples EXAMPLE RUN: PLEASE ENTER A NUMBER TO DISPLAY THE IEEE 754 FLOATING POINT OPTIONS 10.25 PLEASE CHOOSE ONE OF THE FOLLOWING OPERATIONS: 1. DISPLAY THE SIGN BIT VALUE 2. DISPLAY THE INTEGER PART IN BOTH BASE-10 AND BINARY FORMATS 3. DISPLAY THE DECIMAL PART IN BOTH BASE-10 AND BINARY FORMATS 4. DISPLAY THE NUMBER ENTERED IN BOTH BASE-10 AND BINARY FORMATS 5. DISPLAY THE MANTISSA IN BINARY FORMAT 6. DISPLAY THE EXPONENT IN BOTH BASE-10 AND BINARY FORMAT 7. DISPLAY THE IEEE 754 DOUBLE PRECISION BINARY LAYOUT 8. DISPLAY THE IEEE 754 DOUBLE PRECISION HEX LAYOUT 9. SEND THE DETAILED SOLUTION TO AN EXTERNAL FILE 1: SIGN BIT IS (1) SINCE THE NUMBER ENTERED IS NEGATIVE}
return 0;
}
OUTPUT IS SUPPOSED TO BE LIKE EXAMPLE RUN BUT HEX PART DOESNT WORK FOR A NEGATIVE NUMBER
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started