- select the code text.
- click the {} Code button.
- ensure there is an empty trailing line.
Can anyone help me to understand the concept of this code ( IEEE 754 REPRESENTATION
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Rajashree Annapillai
 el 9 de Ag. de 2018
  
    
    
    
    
    Comentada: Rajashree Annapillai
 el 12 de Ag. de 2018
            clc
clear all
close all % Converting input of base 10
format long g
x=randi([1 50],1,1)
%Converting of mantissa (x_1) to between 1 and 2 of base-2 scientific notation
n_exponent=0;
x_1=x;
if abs(x)<1
while abs(x_1)<1
    n_exponent=n_exponent-1;
    x_1=x/(2.^n_exponent);
end
else
    while abs(x_1)>=2
n_exponent=n_exponent+1;
x_1=x/(2.^n_exponent);
    end
end
%Exponent to 8-bit binary (single precision 127)
exp_127=n_exponent+127;
bit8=0;
order=1;
for n=1:8
    bit8=rem(exp_127,2)*order+bit8;
    exp_127=fix(exp_127/2);
    order=order*10;
end
% Converting fraction to 23-bit mantissa (leading 1 hidden)
fraction=x_1-1;
bit23=0;
order1=1;
for n=1:23
    fraction=fraction*2;
    bit23=order1*fix(fraction)+bit23;
    fraction=rem(fraction,1);
    order1=order1*10;
end
%Determining sign of x
sign=0;
if x<0
    sign=1;
end
%Full IEEE 754 binary floating point
N=32;
len=length(sign)+length(num2str(bit8))+length(num2str(bit23))
fprintf('%d', [sign, fliplr(bit8), fliplr(bit23),zeros(1,N-len)])
3 comentarios
  David Goodmanson
      
      
 el 10 de Ag. de 2018
				
      Editada: David Goodmanson
      
      
 el 10 de Ag. de 2018
  
			Hi Rajashree, take a look at https://en.wikipedia.org/wiki/Double-precision_floating-point_format
Respuestas (0)
Ver también
Categorías
				Más información sobre Logical en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


