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
Why research and development in Maintenance Engineering?
Dimas [21]

Answer:

The research and development plays an important role in the maintenance engineering is that it basically improve the equipment maintainability and reliability.

According to the requirement, the system and the equipment needs to be maintain in the  maintenance engineering.

The research and the development basically provide the products and services and also improve the existing products and services of the system in the maintenance engineering.

8 0
3 years ago
Carbon dioxide (CO2) expands isothermally at steady state with no irreversibilities through a turbine from 10 bar, 500 K to 2 ba
xenn [34]

Answer:

The answer to the question above is = 152.02 KJ/Kg

Explanation:

Given:

Temperature at first state, (T1)= 500k

Temperature at second state, (T2)= 500k

The above explains an isothermal process as a thermodynamic process,in which the temperature of the system remains constant

Pressure at first state, (p1) = 10 bar

Pressure at second state, (p2) = 2 bar

The heat transfer=

Qrev/m= T x [s(T2) - s(T1) - R ㏑ (p2 ÷ p1)]

Isothermal means the temperature does not change, while Expansion means the volume has increased.

For the internal isothermal process:

Qrev/m=  T x [- R ㏑ (p2 ÷ p1)]

= 500 x  - (8.314 ÷ 44.01) x In (2 ÷ 10) = 152.02 KJ/Kg

Energy equation at turbine is for the internally reversible isothermal process is:

Q-w = m [( (V2²- V1²) ÷ 2) + g ( Z2 - Z1)]

where w= the most efficient work possible in  J

Neglecting the effect of both potential and kinetic energy

(w/ m) = Qrev/ m

= 152.02 KJ/Kg

4 0
2 years ago
In a long trip what is considered a life line to take with you.
Sophie [7]

Answer:

An emergency kit

Explanation:

The reason I say this is because:

A first aid kit can aid you if you have..

Scars

Cuts

Bruises

So, i would say that The first aid kit is the life line.

5 0
2 years ago
A steam power plant operates on an ideal Rankine cycle with two stages of reheat and has a net power output of 120 MW. Steam ent
uysha [10]

Answer:

a) 40.6%

b)72.19kg/s

Explanation:

The Rankine cycle with two reheat stages has 9 stages in total.

The maximum pressure will be at the first inlet stage of the HP turbine which is stage 3. The minimum pressure will be the exit stage of the condenser because the condenser operates under vacuum pressure which is stage 1.

The following assumptions can be made:

1 - Each component in the cycle is analyzed as an open system operating at steady-state.

  2 - All of the processes are internally reversible.

  3 - The turbine and pump operate adiabatically and are internally reversible, so they are also isentropic.

   4 - Condensate exits the condenser as saturated liquid.

  5 - The effluent from the HP turbine is a saturated vapor.

  6 - No shaft work crosses the system boundary of the boiler or condenser.

   7 - Changes in kinetic and potential energies are negligible

a) The thermal efficiency of the cycle is defined as the work of the cycle divided by the total heat input to the system. The stages that have heat input is stages 2-3, 4-5, 6-7.

For stage 2:

s₁=s₂ assuming isentropic

s_1=0.4762 @ P_1=15MPa

enthalpy will be a compressed liquid so after interpolation

h_2=97.93+(0.4762-0.2932)((180.77-97.93)/(0.5666-0.2932))=153.38kJ/kg

For stage 3:

Superheated steam @ T=500⁰C and P=15MPa

h_3=3310.8kJ/kg

Stage 4:

superheated vapor

P=5MPa

s₃=s₄=6.3480 kJ/kg, we must use interpolation to find h₄

h_4=2925.7-(6.348-6.2111)((3069.3-2925.7)/(6.4516-6.2111))=3007.44kJ/kg

Stage 5:

Superheated steam @ T=500⁰C and P₄=P₅=5 MPa

h_5=3434.7kJ/kg

Stage 6:

Superheated steam at P₆= 1MPa

s₅=s₆

s_6=6.9781

We find h₆ using interpolation from the steam tables:

h_6=2943.1-(6.9781-6.9265)((3051.6-2943.1)/(7.1246-6.9265))=2970.67kJ/kg

Stage 7:

P₇=P₆=1MPa

T=500⁰C superheated steam

h_7=3479.1kJ/kg

The heat into the cycle is:

=(h_3-h_2)+(h_5-h_4)+(h_7-h_6)

=(3310.8-153.38)+(3434.7-3007.44)+(3479.1-2970.67)=4108.74kJ/kg

We can determine the work out by the condenser from stage 9 to stage 1:

Stage 1:

saturated liquid P=5kPa

h_1=137.75kJ/kg

Stage 9:

We assume that its a saturated liquid with quality of 1 at 5kPa and

s₇=s₉ and after interpolation

h_9=2568.53kj/kgK

Qout = [/tex]2568.53-137.75=2430.79kJ/kg[/tex]

The thermal efficiency can be written in terms of qin and qout:

n=1-(q_o/q_i)=1-2430.79/4093.11=0.4061

Efficiency of 40.61%

b)

The mass flow rate can be calculated from the Wnet:

W_n=W_t-W_p

Work of the turbines minus the work of the pumps:

W_n=m((h_3-h_4)+(h_5-h_6)+(h_7-h_9)-(h_1-h_2)

120000=m(1662.33)

m=72.19

mass flow rate of steam is 72.19 kg/s

7 0
3 years ago
A simple ideal Rankine cycle with water as the working fluid operates between the pressure limits of 4 MPa in the boiler and 20
viktelen [127]

Answer:

a) 69,630KW

b) 203 KW

Explanation:

The data obtained from Tables A-4, A-5 and A-6 is as follows:

h_{1} = h_{f,@20KPa} = 251.42 KJ/kg\\v_{1} = v_{f,@20KPa} = 0.001017 KJ/kgK\\\\w_{p,in} = v_{1} * (P_{2} - P_{1})\\w_{p,in} = (0.001017)*(4000-20)\\\\w_{p,in} = 4.05 KJ/kg\\\\h_{2} = h_{1} - w_{p,in} \\h_{2} = 251.42 + 4.05\\\\h_{2}  =  255.47KJ/kg\\\\P_{3} = 4000KPa\\T_{3} = 700 C\\s_{3} = 7.6214 KJ/kgK\\\\h_{3} = 3906.3 KJ/kg\\\\P_{4} = 20 KPa\\s_{3} = s_{4} = 7.6214KJ/kgK\\s_{f} = 0.8320 KJ/kgK\\s_{fg} = 7.0752 KJ/kgK\\\\

x_{4} = \frac{s_{4} - s_{f} }{s_{fg} }  \\\\x_{4} = \frac{7.6214-0.8320}{7.0752} = 0.9596\\\\h_{f} = 251.42KJ/kg \\h_{fg} = 2357.5KJ/kg \\\\h_{4} = h_{f} + x_{4}*h_{fg} = 251.42 + 0.9596*2357.5 = 2513.7KJ/kg\\\\

The power produced and consumed by turbine and pump respectively are:

W_{T,out} = flow(m) *(h_{3} - h_{4}) \\W_{T,out} = 50 *(3906.3-2513.7)\\\\W_{T,out} = 69,630 KW\\\\W_{p,in} = flow(m) *w_{p,in} = 50*4.05 = 203 KW

7 0
3 years ago
Other questions:
  • Q5. A hypothetical metal alloy has a grain diameter of 2.4 x 10-2 mm. After a heat treatment at 575°C for 500 min, the grain dia
    7·1 answer
  • OSHA does not approve individual states to have their own safety and health program.
    15·2 answers
  • 21.13 The index of refraction of corundum (Al2O3) is anisotropic. Suppose that visible light is passing from one grain to anothe
    5·1 answer
  • In the designation of wrought Al alloys, eg. 3m, what does the first digit-3- refer to? A. The main alloying element B. Carbon p
    15·1 answer
  • List two possible reasons the engine oil could have a strong gasoline smell
    15·1 answer
  • Nguyên lý hoạt động của kim phun
    7·1 answer
  • Consider a machine of mass 70 kg mounted to ground through an isolation system of total stiffness 30,000 N/m, with a measured da
    9·1 answer
  • What is the difference between the elements of design and the principles of design? Define at
    7·1 answer
  • How do all the cars work to move?
    9·2 answers
  • What is chemical engieering ?​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!