You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
728 B

% EX3 a)
function x = value(b, d, v, t)
% b: basis
% d: mantissa coefficients
% v: coefficients of the exponent
% t: sign
if b < 2
disp('basis needs to be at least 2!')
return
elseif !(t == -1 || t == 1)
disp('t needs to be 1 or -1!')
return
end
exponent = (t * unConvert(v, b))
prefactor = b ^ exponent
mantissa = unConvertMantissa(d, b)
x = prefactor * mantissa
end
function val = unConvert(n, b)
nums = flip(n)
res = 0
for i = 1:length(n)
res += nums(i) * b^(i-1)
end
val = res
end
function val = unConvertMantissa(m, b)
res = 0
for i = 1:length(m)
res += m(i) * b^(-i)
end
val = res
end