Question: Using the function decimal2binary we converted the decimal number 0.1 to a binary floating point number in engineering notation using 10, 50, and 60 mantissa

Using the function decimal2binary we converted the decimal number 0.1 to a binary floating point number in engineering notation using 10, 50, and 60 mantissa bits and reported the remainders.

Why does Matlab report the remainder as 0 when 60 mantissa bits are used, even though infinitely many bits would be required to convert the decimal number 0.1 into a binary floating point number?

decimal2binary Function:

function [m,p,r] = decimal2binary(x,N)

%Input %x: decimal number to translate %N: number of mantissa bits to use. %output %m: vector of N mantissa bits %p: decimal exponent of the binary floating number %r: remainder

m = zeros(N,1); p = floor(log(x)/log(2)); n = p; x = x-2^n;

for i = 1:N n = p-i; if 2^n <= x m(i) = 1; x = x-2^n; end end

r = x;

end

Then we had to run these (10,50,60 mantissa):

format long; format compact; clc; close all; clear all; [m,p,r] = decimal2binary(0.1,10) fprintf('0.1=1.%s*2^%d with remainder r = %g ',sprintf('%d',m),p,r);

>>0.1=1.1001100110*2^-4 with remainder r = 2.44141e-05

format long; format compact; clc; close all; clear all; [m,p,r] = decimal2binary(0.1,50) fprintf('0.1=1.%s*2^%d with remainder r = %g ',sprintf('%d',m),p,r);

>>0.1=1.10011001100110011001100110011001100110011001100110*2^-4 with remainder r = 2.77556e-17

format long; format compact; clc; close all; clear all; [m,p,r] = decimal2binary(0.1,60) fprintf('0.1=1.%s*2^%d with remainder r = %g ',sprintf('%d',m),p,r);

>>0.1=1.100110011001100110011001100110011001100110011001101000000000*2^-4 with remainder r = 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!