I have made a function convert fractional part of a decimal number to binary, the code is given below:
function [ ret ] = de2bi_( in, itt ) ret=''; for i=1:itt in = mod(in,1); in = in*2; ret = strcat(ret, (num2str(floor(in)))); end return; end
here itt is the number of digits required in binary. But when I pass the value of pi it returns the following value
which is obviously wrong. Same is the case for any other recurring rational or irrational decimal number. How to solve this issue.