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
If the head loss in a 30 m of length of a 75-mm-diameter pipe is 7.6 m for a given flow rate of water, what is the total drag fo
Stolb23 [73]

Answer:

526.5 KN

Explanation:

The total head loss in a pipe is a sum of pressure head, kinetic energy head and potential energy head.

But the pipe is assumed to be horizontal and the velocity through the pipe is constant, Hence the head loss is just pressure head.

h = (P₁/ρg) - (P₂/ρg) = (P₁ - P₂)/ρg

where ρ = density of the fluid and g = acceleration due to gravity

h = ΔP/ρg

ΔP = ρgh = 1000 × 9.8 × 7.6 = 74480 Pa

Drag force over the length of the pipe = Dynamic pressure drop over the length of the pipe × Area of the pipe that the fluid is in contact with

Dynamic pressure drop over the length of the pipe = ΔP = 74480 Pa

Area of the pipe that the fluid is in contact with = 2πrL = 2π × (0.075/2) × 30 = 7.069 m²

Drag Force = 74480 × 7.069 = 526468.1 N = 526.5 KN

3 0
3 years ago
Vital role of maritime english among seaferers
seropon [69]

Answer:

uehgeg7djw7heidiisosowiuisiejei2k

8 0
3 years ago
Calculate the pressure drop in a duct (measured by a differential oil manometer) if the differential height between the two flui
Burka [1]

Answer:

The pressure drop is 269.7N/m^2

Explanation:

∆P = ∆h × rho × g

∆h = 3.2cm = 3.2/100 = 0.032m, rho = 860kg/m^3, g = 9.8m/s^2

∆P = 0.032×860×9.8 = 269.7N/m^2

6 0
3 years ago
Ldentiy three industries that often need the skills of mechanical engineers. Briefly explain the skills that mechanical engineer
const2013 [10]

Answer:

3 industries that often need the skills of mechanical engineers are:

  • Automotive industry
  • Construction industry
  • Aerospace industry

The key skills mechanical engineers bring to these industries are effective technical skills, the ability to work under pressure, problem-solving skills, creativity and teamwork.

Explanation:

Automotive industry: The skills mechanical engineers bring to automotive industry include designing new cars for development, conducting laboratory testing for performance safety, and troubleshooting design or manufacturing issues with recalled vehicles. Automotive engineers have:

  • good mathematical skills, for instance in calculating the stresses power trains and other parts have to withstand;  
  • understanding and application of principles of physics and chemistry to properly design engines, electrical systems and other car components;  
  • good computer skills, because 21st century engineers rely on computer-assisted design software;
  • knowledge of ergonomics, which is applied in the process of designing a car so that the driver and passengers have a comfortable and functional environment, is another skill mechanical; engineers need.

Construction industry: Mechanical engineers are responsible for designing, building, establishing, and maintaining all kinds of mechanical machinery, tools, and components in the construction industry.

Aerospace industry: Mechanical engineers in aerospace industry produce specifications for design, development, manufacture and installing of new or modified mechanical components or systems. They design more fuel-efficient aircraft that cut emissions and build the fleets of satellites that power modern GPS technology.

4 0
3 years ago
The rate of flow through an ideal clarifier is 8000m3 /d, the detention time is 1h and the depth is 3m. If a full-length movable
Fittoniya [83]

Answer:

a) 35%

b) yes it can be improved by moving the tray near the top

   Tray should be located ( 1 to 2 meters below surface )

   max removal efficiency ≈ 70%

c) The maximum removal will drop as the particle settling velocity = 0.5 m/h

Explanation:

Given data:

flow rate = 8000 m^3/d

Detention time = 1h

depth = 3m

Full length movable horizontal tray :  1m below surface

<u>a) Determine percent removal of particles having a settling velocity of 1m/h</u>

velocity of critical sized particle to be removed = Depth / Detention time

= 3 / 1 = 3m/h

The percent removal of particles having a settling velocity of 1m/h ≈ 35%

<u>b) Determine if  the removal efficiency of the clarifier can be improved by moving the tray, the location of the tray  and the maximum removal efficiency</u>

The tray should be located near the top of the tray ( i.e. 1 to 2 meters below surface ) because here the removal efficiency above the tray will be 100% but since the tank is quite small hence the

Total Maximum removal efficiency

=  percent removal_{above} + percent removal_{below}

= ( d_{a},v_{p} ) . \frac{d_{a} }{depth}  + ( d_{a},v_{p} ) . \frac{depth - d_{a} }{depth}  = 100

hence max removal efficiency ≈ 70%

<u>c) what is the effect of moving the tray would be if the particle settling velocity were equal to 0.5m/h?</u>

The maximum removal will drop as the particle settling velocity = 0.5 m/h

7 0
3 years ago
Other questions:
  • What entrepreneurial activities do you know?are you capable of doing entrepreneurial activities
    15·1 answer
  • What are some of the main causes of accidents?
    7·1 answer
  • What do you think are the advantages and disadvantages of isothermal constant volume high extension cycle? And how efficient do
    13·1 answer
  • Two cars A and B leave an intersection at the same time. Car A travels west at an average speed of x miles per hour and car B tr
    9·1 answer
  • How far do you jog each morning? You prefer to jog in different locations each day and do not have a pedometer to measure your d
    14·1 answer
  • How does flextape adhere under water?​
    8·1 answer
  • If you have 300 skittles in a bag and you need to have 28 percent yellow. How many yellow skittles would you have to make a mini
    11·1 answer
  • You need to lower your lift onto the mechanical load-holding devices to provide structural support before working under the lift
    12·1 answer
  • Hi gospelgamer10 lol
    9·2 answers
  • 3. Low-voltage conductors rarely cause<br> injuries.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!