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))));endreturn;end
here itt is the number of digits required in binary. But when I pass the value of pi it returns the following value
0010010000111111011010101000100010000101101000110000000000000000000000000000000000000000000000000000
which is obviously wrong. Same is the case for any other recurring rational or irrational decimal number. How to solve this issue.
Best Answer