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
What is a p-n junction? Show by the diagram.
Natalija [7]

Answer:

The p-n junction is a region formed when a p -type semiconductor material is joined to an n-type semiconductor material

Explanation:

The p type semiconductor has holes as its majority charge carriers making it positively charged while the n –types has an overall negative charge. At the junction the holes move towards the electron until such a time when there is a balance in charges from both materials, which leads to the formation of the depletion zone as shown in the attachment below

                           

5 0
3 years ago
A long, cylindrical, electrical heating element of diameter 10 mm, thermal conductivity 240 W/m·K, density 2700 kg/m3, and speci
Slav-nsk [51]

Answer:

Answer for the question is given in the attachment .

Explanation:

4 0
3 years ago
A large class with 1,000 students took a quiz consisting of ten questions. To get an A, students needed to get 9 or 10 questions
VMariaS [17]

Answer:

a. 0.11

b. 110 students

c. 50 students

d. 0.46

e. 460 students

f. 540 students

g. 0.96

Explanation:

(See attachment below)

a. Probability that a student got an A

To get an A, the student needs to get 9 or 10 questions right.

That means we want P(X≥9);

P(X>9) = P(9)+P(10)

= 0.06+0.05=0.11

b. How many students got an A on the quiz

Total students = 1000

Probability of getting A = 0.11 ---- Calculated from (a)

Number of students = 0.11 * 1000

Number of students = 110 students

So,the number of students that got A is 110

c. How many students did not miss a single question

For a student not to miss a single question, then that student scores a total of 10 out of possible 10

P(10) = 0.05

Total Students = 1000

Number of Students = 0.05 * 1000

Number of Students = 50 students

We see that 5

d. Probability that a student pass the quiz

To pass, a student needed to get at least 6 questions right.

So we want P(X>=6);

P(X>=) =P(6)+P(7)+P(8)+P(9)+P(10)

=0.08+0.12+0.15+0.06+0.05=0.46

So, the probability of a student passing the quiz is 0.46

e. Number of students that pass the quiz

Total students = 1000

Probability of passing the quiz = 0.46 ----- Calculated from (d)

Number of students = 0.46 * 1000

Number of students = 460 students

So,the number of students that passed the test is 460

f. Number of students that failed the quiz

Total students = 1000

Total students that passed = 460 ----- Calculated from (e)

Number of students that failed = 1000 - 460

Number of students that failed = 540

So,the number of students that failed is 540

g. Probability that a student got at least one question right

This means that we want to solve for P(X>=1)

Using the complement rule,

P(X>=1) = 1 - P(X<1)

P(X>=1) = 1 - P(X=0)

P(X>=1) = 1 - 0.04

P(X>=1) = 0.96

7 0
3 years ago
An inductor and resistor are connected in parallel to a 120-V, 60-Hz line. The resistor has a resistance of 50 ohms, and the ind
BARSIC [14]

Answer:

hi

Explanation:

the answer would be I dont know

6 0
3 years ago
A 4-m-high and 6-m-long wall is constructed of twolarge 2-cm-thick steel plates (k 5 15 W/m·K) separated by1-cm-thick and 20-cm
Flura [38]

Answer:

fart

Explanation:

6 0
3 years ago
Other questions:
  • What does the following program segment do? Declare Count As Integer Declare Sum As Integer Set Sum = 0 For (Count = 1; Count &l
    15·1 answer
  • In unguided medium (free space), the electromagnetic (EM) signal wave spreads as it leaves the transmit antenna. Since the power
    10·1 answer
  • A piston-cylinder device contains 0.8 kg of steam at 300°C and 1 MPa. Steam is cooled at constant pressure until one-half of the
    9·1 answer
  • An insulated piston–cylinder device initially contains 1 m3 of air at 120 kPa and 17°C. Air is now heated for 15 min by a 200-W
    7·1 answer
  • What is the difference between CNC and NC​
    15·1 answer
  • Two piezometers have been placed along the direction of flow in a confined aquifer that is 30.0 m thick. The piezometers are 280
    6·1 answer
  • How can goal setting help with academic performance?
    13·1 answer
  • Use pseudocode. 1) Prompt for and input a saleswoman's sales for the month (in dollars) and her commission rate (percentage). Ou
    6·1 answer
  • A heating system must maintain the interior of a building at TH = 20 °C when the outside temperature is TC = 2 °C. If the rate o
    10·1 answer
  • I just wanted to say thanks you to Brainly. This website is a huge help!
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!