//还是递归算法好
先将字符转成数组,如
Function tran(Str1:string):Longint;//二进制字符串转十进制
var
len:byte;
BArr:array of byte;
resu:Longint;
begin
Len:=Length(Str1);
setlength(BArr,len);
for i:=1 to lendo
Barr[i-1]:=StrtoInt(copy(str,i,1));
resu:=0;
for i:=0 to len-1do
resu:=resu*2+Barr;
result:=resu;
end;
然后用:
通用的进制转换函数:
function DigitalTran(number1:longint;InDig,OutDig:Byte):longint;
var
midval,hexx : longint;
begin
midval:=0;
hexx:=1;
repeat
midval := midval + (number1 mod OutDig)*hexx;
number1 := number1 div OutDig;
hexx := hexx*InDig;
until number1 =0 ;
result:= midval;
end;
但如数据太长会溢出;