1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
anyanavicka [17]
3 years ago
6

Programming Assignment 2 Decimal and IEEE-754 ConversionsObjective: 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 DecimalSpecification:The program converts a number based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are:1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) Quit programSpecial Cases The program must also check for these special IEEE cases: • + 0 • -0 • + infinity • - Infinity • NaNSample test runThis sample run contains all possible cases that will be tested, either individually, in their own Test Bench, or combined in a single Test Bench.Test Inputs These are the input test values. They do not appear on the output of the run.1 2.5 2 40200000 1 0 2 -126 2 FFFFFFFF 3Test OutputFloating-point conversion:1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) ExitEnter selection:Enter the decimal representation:*** Sign: 0 *** Biased exponent: 10000000 *** Mantissa: 01000000000000000000000 *** IEEE HEX: 40200000Floating-point conversion:1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) ExitEnter selection:Enter the IEEE-754 representation:*** Sign: + *** Unbiased exponent: 1 *** Normalized decimal: 1.250000 *** Decimal: 2.500000Floating-point conversion: -1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) ExitEnter selection:Enter the decimal representation:*** Sign: 0 *** Biased exponent: 00000000 *** Mantissa: 00000000000000000000000***The IEEE-754 representation is: 0.000000Floating-point conversion:1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) ExitEnter selection:Enter the IEEE-754 representation:*** Sign: - *** Special case: NaNFloating-point conversion:1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) ExitEnter selection:Enter the IEEE-754 representation:*** Sign: - *** Special case: NaNFloating-point conversion:1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) ExitEnter selection:*** Program Terminated Normally"Assignment 2 Skeleton"#include #include /*************************/void "OPTION #1"(){ /* declare local variables */ /* prompt for floating point decimal number */ /* Check for 0--if so, print result */ /* Print sign: if number>0, sign is 0, else 1 */ /* take absolute value of number before generating significand */ /* Normalize number: while number >2, divide by 2, increment exponent while number <1, multiply by 2, decrement exponent */ /* Bias exponent by 127 and print each bit in binary with 8-iteration for-loop*/ /* Hide 1 and print significand in binary with 23-iteration for-loop*/ /* Print IEEE-754 representation */return;}/***********************************************************************/void "OPTION #2"(){/* declare local variables *//* prompt for IEEE-754 representation */ /* check for special cases: 0, -0, +infinity, -infinity, NaN, if so, print and return */ /* Mask sign from number: if sign=0, print "+", else print "-" */ /* Mask biased exponent and significand from number */ /* If biased exponent=0, number is denormalized with unbiased exponent of -126, print denormalized number as fraction * 2^(-126), return */ /* Unbias exponent by subtracting 127 and print */ /* Add hidden 1 and print normalized decimal number */ /* Print decimal number */ return;}int main(){/* declare local variables *//* until user chooses to quit, prompt for choice and select appropriate function */return 0;}
Engineering
1 answer:
kondaur [170]3 years ago
3 0

Answer:

// Program is written in C Programming Language

// Comments are used for explanatory purpose

// Program starts here

#include<stdio.h>

#include<math.h>

//Function to Convert to float

void To float(int num, int I)

{

//Create a kount variable

int kount;

// Start an iteration

for(kount=i-1; kount>0; kount--)

{

if((num>>kount) && 1) {printf("1");}

else { printf("0"); }

}

}

// Create a user defined variable

typedef union {// Definition

float Number;

struct

{

// Mantissa

unsigned int mant : 23;

// Exponent

unsigned int exp : 8;

// Sign

unsigned int sign: 1;

} raw;

} myfloat; // Variable name

// Create print segment

void printsegment(myfloat var)

{

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

To float(var.raw.exp,8); // Exponent

printf("|");

To float(var.raw.mant,8); // Mantissa

printf("\n");

}

// Function to Convert to Real

unsigned int ToReal(int* dig[], int l, int h)

{

unsigned int f = 0, I;

Start an iteration

for(I = h; I>=l;I--)

{

// Calculate individual value

f = f + dig[I] * pow(2,h-1);

}

return f;

}

// Main method start here

int main()

{

printf("Floating Point Conversion\n");

printf("Select any of the following options\n");

printf("1. Decimal to IEEE754 Conversion\n");

printf("2. IEEE754 to Decimal Conversion\n");

printf("3. Quit");

// Declare integer variable for option

int opt;

// Prompt to select option

printf("Select an option; Option 1 to 3: ");

scanf("%d", $opt);

if(opt == 1)

{

printf("You have selected option 1");

// Declare a user defined variable and a system defined variable

myfloat var; float number;

// Accept input

scanf("%d", number);

// Check for special cases

if(isnan(number/0.0))// Not a number

{

printf("Not a Number");

}

else

{

var.f = number;

// Print Sign

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

// Print Exponent

ToFloat(var.raw.exp,8);

printf(" | ");

// Print Mantissa

ToFloat(var.raw.mant,23);

}

}// End of option 1;

// Beginning of option 2

else if(opt == 2)

{

printf("You have selected option 2");

// Declare an array and two integer variables

unsigned int number[32];

int ctrlno, I = 0;

// Accept input by through an iteration

for(int k = 0; k < 32; k++)

{

// Create a label

label: scanf("%d", ctrlno);

// Check for special cases

if(isnan(ctrlno/0.0))// Not a number

{

printf("Not a Number"); I++;

break;

}

else if(ctrlno>1 || ctrlno < 0)

{

printf("Invalid Number\n Please enter a valid digit");

goto label;

}

else {

// Assign number to array

number[k] = ctrlno;

}

// Check validity of number

if(I != 0)

{

printf(" Invalid Number Representation");

}

else

{

// Declare user defined variable

myfloat var;

// Get sign

var.raw.sign = number[0];

// Get mantissa; From to 31

unsigned f = ToReal(number,9,31);

var.raw.mant = f;

// Get exponent; 1 to 8

f = ToReal(number,1,8);

var.raw.exp = f;

// Print Output

printf("The converted digit is ");

printf("%f", var.f);

}

else

{

// Quit Application

break;

}

return 0;

}

You might be interested in
What is the formula for measuring the speed of an object
STALIN [3.7K]
S= d/t
Speed= distance/time
8 0
3 years ago
A water reservoir contains 108 metric tons of water at an average elevation of 84 m. The maximum amount of electric energy that
zavuch27 [327]

Answer:

24.72 kwh

Explanation:

Electric energy=potential energy=mgz where m is mass, g is acceleration due to gravity and z is the elevation.

Substituting the given values while taking g as 9.81 and dividing by 3600 to convert to per hour we obtain

PE=(108*9.81*84)/3600=24.72 kWh

8 0
3 years ago
A copper-nickel alloy of composition 60 wt% Ni-40 wt% Cu is slowly heated from a temperature of 1250°C (2280 °F). (a) At what te
makkiz [27]

Answer:

a. The very first liquid process, when heated from 1250 degree Celsius, is expected to form at the temperature by which the vertical line crosses the phase boundary (a -(a + L)) which is about <em>1310 degree Celsius. </em>

b. The structure of that first liquid is identified by the intersection with ((a+ L)-L) phase boundary; <em>47wt %of Ni</em> is of a tie line formed across the (a+ L) phase area <em>at 1310 degrees.</em>

c. To find the alloy's full melting, it is determined that the intersection of the same vertical line at 60 wt percent Ni with (a -(a+L)) phase boundary is around <em>1350 degrees.</em>

c. The structure of the last remaining solid before full melting correlates to the intersection with the phase boundary (a -(a + L), of the tie line built at 1350 degrees across the (a + L) phase area, <em>being 72wt % of Ni.</em>

4 0
3 years ago
A insulated vessel s has two compartments separated by a membreane. On one side is 1kg of steam at 400 degC and 200 bar. The oth
Lilit [14]

Answer:

See explaination

Explanation:

See attachment for the detailed step by step solution of the given problem.

5 0
3 years ago
A converging nozzle has an exit area of 0.001 m2. Air enters the nozzle with negligible velocity at a pressure of 1 MPa and a te
Artyom0805 [142]

Explanation:

a converging nozzle has an exit area of 0.001 m2. Air enters the nozzle with negligible velocity at a pressure of 1 MPa and a temperature of 360 K. For isentropic flow of an ideal gas with k = 1.4 and the gas constant R = Ru/MW = 287 J/kg-K, determine the mass flow rate in kg/s and the exit Mach number for back pressures

100% (3 ratings)

A_2 = 0.001 m^2 P_1 = 1 MPa, T_1 = 360 k P_2 = 500 kpa p^gamma - 1/gamma proportional T (1000/500)^1.4 - 1/1.4 = (360/T_2) 2^4/14 = 360/T_2 T_2

3 0
3 years ago
Other questions:
  • A well-insulated tank in a vapor power plant operates at steady state. Saturated liquid water enters at inlet 1 at a rate of 125
    6·2 answers
  • Once Joe Martin reports his concerns to senior management at corporate headquarters and requests that the Ethicana plant operati
    8·1 answer
  • Two technicians are discussing the intake air temperature (IAT) sensor. Technician A says that the computer uses the IAT sensor
    9·1 answer
  • How did Atlantis benefit from lessons learned in construction of earlier orbiters?
    9·1 answer
  • 5b. The object George is examining has a mass of 15 grams. What is<br> the density of the object?
    5·1 answer
  • On July 23, 1983, Air Canada Flight 143 required 22,300 kg of jet fuel to fly from Montreal to Edmonton. The density of jet fuel
    8·1 answer
  • Zack's new home is progressing well, and the foundation work is finished. The general contractor stops by Zack's present home to
    11·1 answer
  • Which of the following is not caused by alcohol?
    10·2 answers
  • If 200 amperes flow from the positive terminal of a battery and operate the starter motor, how many amperes will flow back to th
    8·1 answer
  • A pipe fitter would fabricate which one of the following systems?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!