| ||
%2020/12/2 11:42:31
clc
format long
% IEEE754 to dec
a = '40800000'
a = dec2bin(hex2dec(a),32)
M = bin2dec(a(10:32))
E = bin2dec(a(2:9))
x = (-1)^a(1)*(1 + M*2^-23)*2^(E-127)
% dec to IEEE754
result = cos(x)
if(result<0)
S = '1'
else
S= '0'
end
result = abs(result)
i = 0
while(result<1)
result = result * 2
i = i+1
end
j = 0
while(result>2)
result = result/2
j = j+1
end
E = i + j
if(j == 0)
E = -E
end
E = E+127
E = dec2bin(E,8)
result
M23 =dec2bin(floor((result-1)*2^23),23)
r = [S,E,M23]
dec2hex(bin2dec(r))