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
3.94 x 105) + (2.04 x 105)
Flura [38]
627.9 is the answer
6 0
3 years ago
What mass of LP gas is necessary to heat 1.4 L of water from room temperature (25.0 ∘C) to boiling (100.0 ∘C)? Assume that durin
DochEvi [55]

Answer:

m_{LP}=0.45\,kg

Explanation:

Let assume that heating and boiling process occurs under an athmospheric pressure of 101.325 kPa. The heat needed to boil water is:

Q_{water} = (1.4\,L)\cdot(\frac{1\,m^{3}}{1000\,L} )\cdot (1000\,\frac{kg}{m^{3}} )\cdot [(4.187\,\frac{kJ}{kg\cdot ^{\textdegree}C} )\cdot (100^{\textdegree}C-25^{\textdegree}C)+2257\,\frac{kJ}{kg}]

Q_{water} = 3599.435\,kJ

The heat liberated by the LP gas is:

Q_{LP} = \frac{3599.435\,kJ}{0.16}

Q_{LP} = 22496.469\,kJ

A kilogram of LP gas has a minimum combustion power of 50028\,kJ. Then, the required mass is:  

m_{LP} = \frac{22496.469\,kJ}{50028\,\frac{kJ}{kg} }

m_{LP}=0.45\,kg

6 0
3 years ago
An air-standard Diesel cycle engine operates as follows: The temperatures at the beginning and end of the compression stroke are
Vika [28.1K]

This question is incomplete, the complete question is;

An air-standard Diesel cycle engine operates as follows: The temperatures at the beginning and end of the compression stroke are 30 °C and 700 °C, respectively. The net work per cycle is 590.1 kJ/kg, and the heat transfer input per cycle is 925 kJ/kg. Determine the a) compression ratio, b) maximum temperature of the cycle, and c) the cutoff ratio, v3/v2.

Use the cold air standard assumptions.

Answer:

a) The compression ratio is 18.48

b) The maximum temperature of the cycle is 1893.4 K

c) The cutoff ratio, v₃/v₂ is 1.946

Explanation:

Given the data in the question;

Temperature at the start of a compression T₁ = 30°C = (30 + 273) = 303 K

Temperature at the end of a compression T₂ = 700°C = (700 + 273) = 973 K

Net work per cycle W_{net = 590.1 kJ/kg

Heat transfer input per cycle Qs = 925 kJ/kg

a) compression ratio;

As illustrated in the diagram below, 1 - 2 is adiabatic compression;

so,

Tγ^{Y-1 = constant { For Air, γ = 1.4 }

hence;

⇒ V₁ / V₂ = ( T₂ / T₁ )^{\frac{1}{Y-1}

so we substitute

⇒ V₁ / V₂ = (  973 K / 303 K  )^{\frac{1}{1.4-1}

= (  3.21122  )^{\frac{1}{0.4}

= 18.4788 ≈ 18.48

Therefore, The compression ratio is 18.48

b) maximum temperature of the cycle

We know that for Air, Cp = 1.005 kJ/kgK

Now,

Heat transfer input per cycle Qs = Cp( T₃ - T₂ )

we substitute

925 = 1.005( T₃ - 700 )

( T₃ - 700 ) = 925 / 1.005

( T₃ - 700 ) = 920.398

T₃ = 920.398 + 700

T₃ = 1620.398 °C

T₃ = ( 1620.398 + 273 ) K

T₃ = 1893.396 K ≈ 1893.4 K

Therefore, The maximum temperature of the cycle is 1893.4 K

c)  the cutoff ratio, v₃/v₂;

Since pressure is constant, V ∝ T

So,

cutoff ratio S = v₃ / v₂  = T₃ / T₂

we substitute

cutoff ratio S = 1893.396 K / 973 K

cutoff ratio S = 1.9459 ≈ 1.946

Therefore, the cutoff ratio, v₃/v₂ is 1.946

8 0
3 years ago
The steel bracket is used to connect the ends of two cables. if the allowable normal stress for the steel is sallow = 30 ksi, de
garri49 [273]

The largest tensile force that can be applied to the cables given a rod with diameter 1.5 is 2013.15lb

<h3>The static equilibrium is given as:</h3>

F = P (Normal force)

Formula for moment at section

M = P(4 + 1.5/2)

= 4.75p

Solve for the cross sectional area

Area = \frac{\pi d^{2} }{4}

d = 1.5

\frac{\pi *1.5^{2} }{4}

= 1.767 inches²

<h3>Solve for inertia</h3>

\frac{\pi *0.75^4}{4}

= 0.2485inches⁴

Solve for the tensile force from here

\frac{F}{A} +\frac{Mc}{I}

30x10³ = \frac{P}{1.767} +\frac{4.75p*0.75}{0.2485} \\\\

30000 = 14.902 p

divide through by 14.902

2013.15 = P

The largest tensile force that can be applied to the cables given a rod with diameter 1.5 is 2013.15lb

Read more on tensile force here: brainly.com/question/25748369

4 0
2 years ago
You were hoping to receive a scholarship for volleyball and are entering your personal information and statistics on a secure we
kozerog [31]
I think it is fair to say 5 and 3/4 inches.
6 0
3 years ago
Read 2 more answers
Other questions:
  • g A plane stress element has components sigma x = 160 MPa, tau xy = 100 MPa (CW). Determine the two values pf sigma y for which
    13·1 answer
  • A piece of corroded steel plate was found in a submerged ocean vessel. It was estimated that the original area of the plate was
    12·1 answer
  • The fan blades suddenly experience an angular acceleration of 2 rad/s2. If the blades are rotating with an initial angular veloc
    10·1 answer
  • The grade is a measure of quality and it captures concentration levels (i.e., how pure a certain fraction is). If grade captures
    13·1 answer
  • A 10-mm-diameter Brinell hardness indenter produced an indentation 2.50 mm in diameter in a steel alloy when a load of 1000 kg w
    12·1 answer
  • Please help! timed test. This about electrical control. Please be serious.
    15·1 answer
  • Two kilograms of air in a piston-cylinder assembly undergoes an isothermal
    11·1 answer
  • one number is 11 more than another number. find the two number if three times the larger number exceeds four times the smaller n
    14·1 answer
  • The design-bid-build model is prons to abuse because separation of phases facilitates the hiding of corrupt practices.
    7·2 answers
  • (a) calculate the moment at point "c", where point "c" is the square 3'' below the centroid
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!