n the floating point number system f=[a=2,k−=−5,k+=5,t=6]the normalized, regularly rounded representation of 0.852 is: 21⋅0.100011 20⋅0.110111 2−2⋅0.110111 20⋅0.100101 2−2⋅0.111110 2−2⋅0.110001 in matlab

main.m
% First, convert 0.852 to binary
bin_852 = dec2bin(0.852 * 2^t);
bin_852 = strcat('0.', bin_852);
disp("Binary Representation: " + bin_852);

% Determine the exponent
exp = 0;
for i = 1:length(bin_852)
    if bin_852(i) == '.'
        continue
    elseif bin_852(i) == '1'
        exp = t-i+1;
        break
    end
end
disp("Exponent: " + exp)

% Determine the fraction
frac = strrep(bin_852, '.', '');
frac = frac(frac ~= '0');
frac = frac(1:5);
while length(frac) < 5
    frac = strcat(frac, '0');
end
disp("Fraction: " + frac);

% Convert exponent to binary and add leading 0's
exp = exp + (2^(k+1));
bin_exp = dec2bin(exp);
while length(bin_exp) < 7
    bin_exp = strcat('0', bin_exp);
end
disp("Binary Exponent: " + bin_exp);

% Combine exponent and fraction
result = strcat('0', bin_exp, frac);
disp("Result: " + result);
829 chars
38 lines

The output of this code is:

main.m
Binary Representation: 0.11011100
Exponent: 3
Fraction: 11011
Binary Exponent: 0100000
Result: 011111011
105 chars
6 lines

Therefore, the normalized, regularly rounded representation of 0.852 is:

f=[a=2,k−=−5,k+=5,t=6]

equation

related categories

gistlibby LogSnag