Explanation of Solution
Function definition for “float_i2f()” function:
The implementation for “float_i2f()”function is given below:
//Header file
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//Declare the float_bits in unsigned data type
typedef unsigned float_bits;
//Function declaration for float_i2f function
float_bits float_i2f(int i);
//Function definition for compute the bit length
int findBitsLength(int i)
{
//Check bit length
if ((i & INT_MIN) != 0)
{
//Returns value "32"
return 32;
}
//Assign the unsigned number
unsigned unum = (unsigned)i;
//Initializes the length is "0"
int len = 0;
//Check the length
while (unum >= (1<<len))
{
len++;
}
//Returns the length
return len;
}
//Function definition to generate mask
unsigned findBitsMask(int bl)
{
//Returns the bits mask
return (unsigned) -1 >> (32-bl);
}
//Fnction definition for compute (float)i
float_bits float_i2f(int i)
{
//Declare variable
unsigned signBit, exponentBit, fractionBit, remainingBit, exp_signBit,rp;
//declare variable bits and float bits
unsigned b, fb;
//Assign bias value
unsigned biasValue = 0x7F;
//If "i" is "0", then
if (i == 0)
{
//Assign all bits to "0"
signBit = 0;
exponentBit = 0;
fractionBit = 0;
//Returns the value
return signBit << 31 | exponentBit << 23 | fractionBit;
}
//If "i" is "INT_MIN", then
if (i == INT_MIN)
{
//Assign given value to each bit
signBit = 1;
exponentBit = biasValue + 31;
fractionBit = 0;
//Returns the value
return signBit << 31 | exponentBit << 23 | fractionBit;
}
//Assign sign bit is "0"
signBit = 0;
/* For two's complement */
/* If "i" is less than "0", then */
if (i < 0)
{
//Assign sign bit to "1"
signBit = 1;
//Assign "i" to "i - i"
i = -i;
}
/* Compute bits length by calling function "findBitsLength" */
b = findBitsLength(i);
//Compute float bits
fb = b - 1;
//Compute exponent value
exponentBit = biasValue + fb;
//Compute remaining bit value
remainingBit = i & findBitsMask(fb);
//If "fb" is less than "23", then
if (fb <= 23)
{
//Assign fraction bit and except bit value
fractionBit = remainingBit << (23 - fb);
exp_signBit = exponentBit << 23 | fractionBit;
}
//Otherwise
else
{
//Compute offset value
int offsetValue = fb - 23;
//To find round middle value
int rm = 1 << (offsetValue - 1);
//For round part
rp = remainingBit & findBitsMask(offsetValue);
//Assign fraction bit and except bit value
fractionBit = remainingBit >> offsetValue;
exp_signBit = exponentBit << 23 | fractionBit;
/*Check if it is round to even */
if (rp < rm)
{
}
//If round to odd, then
else if (rp > rm)
{
...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
- F = A +B'C which one of the followings is the representation of function F in terms of SOP form? F(A,B,C)= m0+m2+m3 F(A,B,C)= M0+M2+M3 F(A,B,C) = M1+M4+M5+M6+M7 F(A,B,C) = m1+m4+m5+m6+m7arrow_forwardQ11/ A function f(t) is said to be even if: Oa) f(t) = f(-t) Ob) f(t) = -f(-t) Oc) f(t) # f(-t) %3D Od) None of thesearrow_forwardIN C PROGRAMMING LANGUAGE AND COMMENT EVERY LINE PLEASE SO I CAN UNDERSTAND EVERY STEP , Write a program that accept two (3 x 3) matrices from the user and then ask the user to select one operation to do: a. Multiplication. b. Addition. c. Subtraction. d. Transpose. The program should print the output as a (3 x 3) matrix.arrow_forward
- Write a function Infix_to_Prefix that takes an arithmetic expression in Infix notation as a parameter and returns the corresponding arithmetic expression with Prefix notation. Note: Question explanation, sample input and output are attached below. Kindly answer this question using pythonarrow_forwardQuestion VI: Write a program that computes and plots the spectral representation of the function 1. y(t) = (10e-10t)u(t) 2. y(t) = (10e-10t cos100t)u(t)arrow_forward4. Using bitwise operators In C code Write a function int negate(int n) that can negate an integer without using the - operator.arrow_forward
- Question 1 - Write a function to reverse the bits in a byte. /// Reverses the bits in a byte /// @param x- the input byte /// @return the same byte with the bits reversed uint8_t reverse_bits (uint8_t x) {arrow_forwarda) What is "Approximation Error" in floating-point representation? Approximation Error - Since in floating point representation we can not represent all real numbers so there occurs an error.It is difficult to represent some decimal numbers in binary form. b) Why is it happening? Floating point Approximation error occur because it uses fixed no. of bits to represent decimal numbers. It is difficult to represent real numbers with the help of fixed bits of binary numbers. Also some decimal numbers are difficult to represent in binary form. c) How can we minimize it? We can minimise it by- 1.Changing radix 2.Adding numbers of different magnitude value. 3.overflow 4. underflow 5.Subtracting numbers of same magnitude value. Dont use answers from other websites please! Please type your answer not picture d) How can the character codes be a solution for this?arrow_forwardWrite a function int Factorial(int n) to calculate factorial of n. If n is non negative then it return factorial, otherwise it display a proper error message and return -1.arrow_forward
- Given a Binary Number B, find its decimal equivalent. Example 1: Input: B = 10001000 Output: 136 Example 2: Input: B = 101100 Output: 44 Your Task: You don't need to read or print anything. Your task is to complete the function binary_to_decimal() which takes the binary number as string input parameter and returns its decimal equivalent. Expected Time Complexity: 0(K* Log(K)) where K is number of bits in binary number. Expected Space Complexity: 0(1)arrow_forwardWrite a function that prints the ASCII values of the char- acters using the following header: void printASCII(char ch1, char ch2, int numberPerLine) This function prints the ASCII values of characters between ch1 and ch2 with the specified number of characters per line. Write a test program that prints 6 ASCII values per line of characters from 'a' to 'm'.arrow_forward2. Write a recurrence relation describing the worst case running time of each of the following algorithms and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution. You may not use the Master Theorem as justification of your answer. Simplify and express your answer as (nk) or (nk log₂ n) whenever possible. If the algorithm is exponential just give exponential lower bounds. a) function func(A,n) if n ≤ 5 then return A(1) else for i=1 to n for j = i to n-1 A(j) A(j) + A(i) + 3 /* endfor */ /* endfor */ wwwwwwwwww y ← func(A, n-6) return (y)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education