//求二進位值轉十進位字串 //DEMO:Get2to10('11011'):= 27; function Get2to10(S: string): Double; var i, Len: Integer; begin Result := 0; Len := Length(S); for i := 1 to Len do begin if Pos(Copy(S, i, 1), '10') = 0 then begin Result := 0; Break; end else Result := Result + StrToInt(Copy(S, i, 1)) * (Power(2, (Len - i))); end; end;
//DEMO:Get2to10('11011'):= 27;
function Get2to10(S: string): Double;
var
i, Len: Integer;
begin
Result := 0;
Len := Length(S);
for i := 1 to Len do
begin
if Pos(Copy(S, i, 1), '10') = 0
then
begin
Result := 0;
Break;
end
else
Result := Result + StrToInt(Copy(S, i, 1)) * (Power(2, (Len - i)));
end;
end;
你要在uses里加上Math
uses Math;
有问题请发信息到我的E-mail:[email protected]
有问题请发信息到我的E-mail:[email protected]