%THIS FUNCTION TAKES A USER INPUT IN BINARY AND OUTPUTS ITS DECIMAL
%CONVERSION
%OTERO, ALIANJECON
%2025/5/29
clc, clear, close all;

function bin2dec(num)
if ~ischar(num)
    num = num2str(num, "%.16f");
    num = convertStringsToChars(num);
end
w = [];
d = [];

decw = 0;
decd = 0;

i = 1;
while i <= size(num,2) && num(i) ~= '.'
    w = [w, num(i)];
    i = i + 1;
end

i = i + 1;

while i <= size(num,2)
    d = [d, num(i)];
    i = i + 1;
end

d

for i = size(w,2):-1:1
    decw = decw + (w(i) - 48) * 2^(size(w,2)-i);
end

for i = 1:size(d,2)
    decw = decw + (d(i) - 48) * 1/(2^(i));
end

if floor(decw) == decw
    fprintf("%d",decw);
else
fprintf("%.16f",decw);
end

end

num = input("Number\n");

bin2dec(num);
