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]
4 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]4 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
9 b. A sign (including the post and base) weighs 40 pounds and is
tigry1 [53]

Answer:

The weight should be added to the base of the sign to keep it from tipping is 65.6 lb

Explanation:

Given data:

A sigh weighs 40 pounds

Suported by an 18 in x 18 in square

Force of the wind 13.2 lb

Questions: Will the sign tip over, if yes, how much evelnly distributed weight should be added to the base of the sign to keep it from tipping, W = ?

The sign and the post have a length of 6 ft. You need to calculate the distance from the edge to the middle point:

18/2 = 9 in = 0.75 ft

Force acting in the base (40 lb):

F=\frac{40*0.75}{6} =5lb

The weight should be added to the base:

(40+W)*\frac{0.75}{6} =13.2\\W=65.6lb

8 0
4 years ago
An uncharged capacitor and a resistor are connected in series to a source of voltage. If the voltage = 7.41 Volts, C = 11.5 µFar
Musya8 [376]

Answer:

a) RC = 1.03 mseg.

b) Qmax = CV = 85.2 μC

c) Q = 53.9 μC

Explanation:

a) In a RC circuit, during the transient period, the capacitor charges exponentially (starting from 0 due to the voltage in the capacitor can´t change instantaneously) with time, being the exponent -t/RC.

This product RC, which defines the rate at which the capacitor charges, is called the time constant of the circuit.

In this case , it can be calculated as follows:

ζ = R C = 89.4 Ω . 11.5 μF = 1.03 mseg.

b) As the charge begins to build up the capacitor plates, a voltage establishes between plates, that opposes to the battery voltage. When this voltage is equal to the battery one, the capacitor reaches to the maximum charge, which is, by definition, as follows:

Q = C V = 11.5 μF . 7.41 V = 85.2 μC

c) During the charging process, the charge increases following this equation:

Q = CV (1 - e⁻t/RC)

When t = RC, the expression for Q is as follows:

Q = CV ( 1- e⁻¹) = 0.63 x CV = 53.9 μC

6 0
4 years ago
An AM radio transmitter radiates 550 kW at a frequency of 740 kHz. How many photons per second does the emitter emit?
kifflom [539]

Answer:

1121.7 × 10³⁰ photons per second

Explanation:

Data provided in the question:

Power transmitted by the AM radio,P = 550 kW = 550 × 10³ W

Frequency of AM radio, f = 740 kHz = 740 × 10³ Hz

Now,

P = \frac{NE}{t}

here,

N is the number of photons

t is the time

E = energy = hf

h = plank's constant = 6.626 × 10⁻³⁴ m² kg / s

Thus,

P = \frac{NE}{t} = \frac{N\times(6.626\times10^{-34}\times740\times10^{3})}{1}          [t = 1 s for per second]

or

550 × 10³ = \frac{N\times(6.626\times10^{-34}\times740\times10^{3})}{1}

or

550 = N × 4903.24 × 10⁻³⁴

or

N = 0.11217 × 10³⁴ = 1121.7 × 10³⁰ photons per second

7 0
3 years ago
A particular motor rotates at 3000 revolutions per minute (rpm). What is its speed in rad/sec, and how many seconds does it take
raketka [301]

Answer:

ω=314.15 rad/s.

0.02 s.

Explanation:

Given that

Motor speed ,N= 3000 revolutions per minute

N= 3000 RPM

The speed of the motor in rad/s given as

Now by putting the values in the above equation

ω=314.15 rad/s

Therefore the speed in rad/s will be 314.15 rad/s.

The speed in rev/sec given as

ω= 50 rev/s

It take 1 sec to cover 50 revolutions

That is why to cover 1 revolution it take

\dfrac{1}{50}=0.02\ s

5 0
4 years ago
Read 2 more answers
While walking across campus one windy day, an engineering student speculates about using an umbrella as a "sail" to propel a bic
makvit [3.9K]

Answer:

Given data:\\While walking across campus one windy day\\Frontal area, \(A=0.3 m ^{2}\)\\Wind speed \(V=24 Km / hr\)\\The drag coefficient \(C_{D, b}=1.2\)\\The combined mass \(m=75 kg\)\\Umbrella diameter, \(D=1.22 m\)\\Velocity of wind \(V=24 \frac{ km }{ hr }\)\\The rolling resistance \(C_{R}=0.75 \%\)

Solution:

Note: Refer the diagram

Basic equation:\\'s law of motion: \(\sum F_{x}=m a_{x}\)\\Lift coefficient, \(C_{L}=\frac{F_{L}}{\frac{1}{2} \rho V^{2} A_{p}}\)\\Drag coefficient, \(C_{D}=\frac{F_{D}}{\frac{1}{2} \rho V^{2} A_{p}}\)

From force balance equation:\\\(\sum F_{x}=F_{D}-F_{R}=0\)\\But \(F_{D}=\left(C_{D, \alpha} A_{u}+C_{D, B} A_{b}\right) \frac{1}{2} \rho\left(V_{\nu}-V_{b}\right)^{2}\)\(F_{R}=C_{R} m g\)\\Area of the Umbrella \(A_{u}=\frac{\pi D_{u}^{2}}{4}\)\(A_{x}=\frac{\pi \times 1.22^{2}}{4} m ^{2}\)\(A_{v}=1.17 m ^{2}\)

Drag coefficient data for selected objects table at

Hemisphere (open end facing flow), C_{D, x}=1.42

Substituting all parameters,

\begin{aligned}&F_{R}=0.0075 \times 75 \times 9.81\\&F_{R}=5.52 N\end{aligned}

Then,

\begin{aligned}&V_{b}=V_{w}-\left[\frac{2 F_{R}}{\rho\left(C_{D, w} A_{w}+C_{D, B} A_{b}\right)}\right]^{\frac{1}{2}} \dots\\&V_{w}=24 \times 1000 \times \frac{1}{3600}\\&V_{w}=6.67 \frac{ m }{ s }\end{aligned}

And the equation becomes,

\begin{aligned}&V_{b}=6.67-\left[\frac{2 \times 5.52}{1.23(1.42 \times 1.17+1.2 \times 0.3)}\right]^{\frac{1}{2}}\\&V_{b}=6.67-2.11\\&V_{b}=4.56 \frac{ m }{ s }\end{aligned}

Thus the floyds travels at 68.3^{\circ}wind speed.

7 0
4 years ago
Other questions:
  • Flue gases from an incinerator are released to atmosphere using a stack that is 0.6 m in diameter and 10.0 m high. The outer sur
    12·1 answer
  • Define factor of safety and its significance
    5·1 answer
  • Welding never causes residual stresses in the work piece, which may result in distortion stress corrosion cracking, and reduced
    10·1 answer
  • Two 2.30 cm × 2.30 cm plates that form a parallel-plate capacitor are charged to ± 0.708 nC . Part A What is the electric field
    7·1 answer
  • A piston-cylinder device contains 0.1 [kg] of air at a pressure of 100 [kPa] and a temperature of 400 [K] that undergoes an expa
    14·1 answer
  • An automobile having a mass of 1100 kg initially moves along a level highway at 110 km/h relative to the highway. It then climbs
    7·1 answer
  • Can someone help me with this maze shown below.
    8·1 answer
  • What plane is this? and when was it made?
    11·1 answer
  • A voltage _______ is an increase or decrease in the normal line voltage within the range of 5% to -10%.
    9·1 answer
  • This graph shows the US unemployment rate from<br> August 2010 to November 2011
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!