write a code in MATLAB that converts from decimal to IEEE754

write a code in MATLAB that converts from decimal to IEEE-754 64 bit double precision

Solution

function [out] = IEEE754Converter(N) if N==0 s= 0; e=0; f=0; out= \'00000000000000000000000000000000\'; else % assign sign value if N<0 s = \'1\'; else s = \'0\'; end % take absolute value of N since we know sign already N = abs(N); % get exponent (unbiased and in decimal) e_temp = floor(log2(N)); % turn e to binary e = dec2bin(127+e_temp); % get fraction (in decimal, lose the 1) f_temp = N-floor(N); % start f as empty f = []; % loop through decimal places for i = 1:23 if f_temp>2^-i % check if fraction is big enough to have non-zero place holder % for 2^-i, then this place holder has a 1. f = [f,\'1\']; % remove placed decimal value from f_temp for future % iterations. f_temp = f_temp-1; else % in this case, this binary placeholder is 0 f = [f,\'0\']; end end out= [s e f]; %Do Not change the lines after this if (N~=0) find (out==\'1\') end end % end IEEE75Converter end
write a code in MATLAB that converts from decimal to IEEE-754 64 bit double precisionSolution function [out] = IEEE754Converter(N) if N==0 s= 0; e=0; f=0; out=

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site