Question: A method for determining the first m digits 0 . b 1 b 2 b 3 . . . bm of the binary representation of
A method for determining the first m digits bbbbm of the binary representation of a real number
x in is the following algorithm:
c x
for j from to m do
bj floorc
c c bj where floorx is the greatest integer less than or equal to the real number x and represents
multiplication.
a Explain how this algorithm works.
b Write a C function that implements this algorithm. The prototype of your function should be
void getbinarydouble x int b int m;
where x is the real number in double precision floating point representation, b is the starting
address of an array of integers, and m is the number of digits we want to obtain. You will need
to include the header file mathh; also include the stdioh header:
#include
#include
Test your function with the following main function:
int main
int b;
getbinary b;
forint i ; i ; i
printfd bi;
return ;
PLEASE NOTE: Even though the pseudocode representation of the algorithm indexes the array of
digits starting at CC always starts indexing at Make sure to write your code so that the
calculations are performed correctly.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
