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
For the same cross-sectional area, which column provides the higher buckling load: a circular bar or a circular tube?
juin [17]

Answer:

Circular tube

Explanation:

Now for better understanding lets take an example

Lets take

Diameter of solid bar= 4\sqrt{2} cm

Outer diameter of tube =6 cm

Inner diameter of tube=2 cm

So from we can say that both tubes have equal cross sectional area.

We know that buckling load is given as P = \dfrac{\pi ^2EI}{L_e^2}      

If area moment of inertia(I) is high then buckling load will be high.

We know that  area moment of inertia(I)

For circular tube I = \dfrac{\pi }{64}(D_o^4-D_i^4)

For circular bar I = \dfrac{\pi }{64}D^4  

Now by putting the values

    For circular tube I=62.83 cm^4

  For circular bar I=50.26 cm^4

So we can say that for same cross sectional area the  area moment of inertia(I) is high for tube as compare to bar.So buckling load  will be higher in tube as compare to bar.

3 0
3 years ago
A manufacturer makes two types of drinking straws: one with a square cross-sectional shape, and the other type the typical round
Harlamova29_29 [7]

Answer:

\frac{Q_{square}}{Q_{circle}} =  0.785  

Explanation:

given data

types of drinking straws

  1. square cross-sectional shape
  2. round shape

solution

we know that both perimeter of the cross section are equal

so we can say that

perimeter of square  = perimeter of circle  

4 × S = π × D

here S is length and D is diameter

S = \frac{\pi D}{4}        ....................1

and

ratio of  flow rate through the square and circle is here

\frac{Q_{square}}{Q_{circle}} = \frac{AV^2}{AV^2}  

\frac{Q_{square}}{Q_{circle}} = \frac{S^2}{\frac{\pi D^2}{4}}  

\frac{Q_{square}}{Q_{circle}} = \frac{(\frac{\pi D}{4})^2}{\frac{\pi D^2}{4}}  

\frac{Q_{square}}{Q_{circle}} = \frac{\pi }{4}  

\frac{Q_{square}}{Q_{circle}} =  0.785  

4 0
4 years ago
What are the factors of production in business? Land, labor, and capital land, capital, and interest land, labor, and customer b
kozerog [31]

Answer:

  • <em><u> Land, labor, and capital </u></em>

Explanation:

The <em>factors of production </em>are the resources that are used to produce goods and services.

By definition resources are scarce.

<em>Land</em> includes everything that comes from the land, that can be used as raw material to produce other materials; for instance, water, minerals, wood.

<em>Labor</em>  is the work done by anybody, not just at a factory but at any enterpise that produce a good or a service. For instance, the work done by a person in a bank or a restaurant.

<em>Capital</em> is the facilites (buildings), machinery, equipments, tools that the persons use to produce goods or services. For instance, a computer, a chemical reactor, or a pencil.

Nowadays, also entrepreneurship is included as a <em>factor of production</em>, since it is the innovative skill of the entrepeneurs to combine land, labor and capital what permit the production of good and services.

6 0
4 years ago
Read 2 more answers
Six housing subdivisions within a city area are target for emergency service by a centralized fire station. Where should the new
Marina86 [1]

Answer:

Explanation:

Since there are six points, the minimum distance from all points would be the centroid of polygon formed by A,B,C,D,E,F

To find the coordinates of centroid of a polygon we use the following formula. Let A be area of the polygon.

C_{x}=\frac{1}{6A} sum(({x_{i} +x_{i+1})(x_{i}y_{i+1}-x_{i+1}y_{i}))     where i=1 to N-1 and N=6

C_{y}=\frac{1}{6A} sum(({y_{i} +y_{i+1})(x_{i}y_{i+1}-x_{i+1}y_{i}))

A area of the polygon can be found by the following formulaA=\frac{1}{2} sum(x_{i} y_{i+1} -x_{i+1} y_{i}) where i=1 to N-1

A=\frac{1}{2}[ (x_{1}  y_{2} -x_{2}  y_{1})+ (x_{2}  y_{3} -x_{3}  y_{2})+(x_{3}  y_{4} -x_{4}  y_{3})+(x_{4}  y_{5} -x_{5}  y_{4})+(x_{5}  y_{6} -x_{6}  y_{5})]

A=0.5[(20×25 -25×15) +(25×32 -13×25)+(13×21 -4×32)+(4×8 -18×21)+(18×14 -25×8)

A=225.5 miles²

Now putting the value of area in Cx and Cy

C_{x} =\frac{1}{6A}[ [(x_{1}+x_{2})(x_{1}  y_{2} -x_{2}  y_{1})]+ [(x_{2}+x_{3})(x_{2}  y_{3} -x_{3}  y_{2})]+[(x_{3}+x_{4})(x_{3}  y_{4} -x_{4}  y_{3})]+[(x_{4}+x_{5})(x_{4}  y_{5} -x_{5}  y_{4})]+[(x_{5}+x_{6})(x_{5}  y_{6} -x_{6}  y_{5})]]

putting the values of x's and y's you will get

C_{x} =15.36

For Cy

C_{y} =\frac{1}{6A}[ [(y_{1}+y_{2})(x_{1}  y_{2} -x_{2}  y_{1})]+ [(y_{2}+y_{3})(x_{2}  y_{3} -x_{3}  y_{2})]+[(y_{3}+y_{4})(x_{3}  y_{4} -x_{4}  y_{3})]+[(y_{4}+y_{5})(x_{4}  y_{5} -x_{5}  y_{4})]+[(y_{5}+y_{6})(x_{5}  y_{6} -x_{6}  y_{5})]]

putting the values of x's and y's you will get

C_{y} =22.55

So coordinates for the fire station should be (15.36,22.55)

5 0
3 years ago
The melting point of Pb (lead) is 327°C, is the processing at 20°C hot working or cold working?
bonufazy [111]

Answer:

Explained

Explanation:

Cold working: It is plastic deformation of material at temperature below   recrystallization temperature. whereas hot working is deforming material above the recrystallization temperature.

Given melting point temp of lead is 327° C and lead recrystallizes at about

0.3 to 0.5 times melting temperature which will be higher that 20°C. Hence we can conclude that at 20°C lead will under go cold working only.

6 0
3 years ago
Other questions:
  • Question Set 22.1 Using the count method, find the number of occurrences of the character 's' in the string 'mississippi'.2.2 In
    10·1 answer
  • What is temperature coefficient of resistance
    12·1 answer
  • Consider two water tanks filled with water. The first tank is 8 m high and is stationary, while the second tank is 2 m high and
    12·2 answers
  • The ventilating fan of the bathroom of a building has a volume flow rate of 32 L/s and runs continuously. If the density of air
    7·1 answer
  • ?Why the efficiency of Class A amplifier is very poor​
    11·1 answer
  • What Number Am I?
    13·1 answer
  • If fog is so bad that I can’t see for short distance what should I do
    9·2 answers
  • (Architecture) Sarah is an environmental activist. She frequently conducts various programs and activities in her community to p
    15·1 answer
  • 9. Imagine that you're performing measurements on a circuit with a multimeter. You measure a total circuit
    14·2 answers
  • A jet of water 75m in diameter,issues with a velocity of 30m/s and impinge on a stationary plate which distort its forward motio
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!