program btod2;
var
b:string;
str1:char;
i,p,leftofdot,rightofdot:integer;dot:boolean;
a1,a2:array [1..20] of integer;
d,y:real;
begin
write('Input the Binary Number:');readln(b);
p:=pos('.',b);
if p=0 then b:=b+'.';
if p=1 then b:='0'+b;
dot:=false;
for i:=1 to length(b) do
begin
if b[i]='.' then
begin
dot:=true;
leftofdot:=i-1
end
else
begin
if dot then
begin
str1:=b[i];
a2[i-leftofdot-1]:=ord(str1)-48;
end
else
begin
str1:=b[i];
a1[i]:=ord(str1)-48;
end;
end;
end;
for i:=1 to leftofdot do write(a1[i]);
write(' . ');
for i:=1 to length(b)-leftofdot-1 do write(a2[i]);
writeln;
y:=1;d:=a1[leftofdot];
for i:=leftofdot-1 downto 1 do
begin
y:=y*2;
d:=d+a1[i]*y;
end;
y:=1;
for i:=1 to length(b)-leftofdot-1 do
begin
y:=y/2;
d:=d+a2[i]*y;
end;
writeln(d:10:5)
end.
本站文章皆为作者原创,其它媒体(包括但不限于报刊、杂志、网站、电视、电台)未经作者书面许可严禁转载(或部分摘录)!
