任意进制(2-36内)与十进制间的转换
来源:互联网 发布:windows net snmp 编辑:程序博客网 时间:2024/05/19 09:15
const DD='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';function DecimalToStr(n :Integer;jz :Byte):string;var m:Integer;begin Result :=''; while (n>jz) and (jz>1) do begin m := n mod jz; n := n div jz; Result := DD[m+1] + Result; end; Result := DD[n+1] + Result;end;function StrToDecimal(s :string;jz:Byte):Integer; //返回一个基础数B的E次方 function IntPower(b,e:Integer):Integer; var i :Integer; begin Result := 1; for I := 1 to e do Result := Result * b; end;var I,L:Integer;begin Result :=0; s := UpperCase(s); L := Length (s); for I := 1 to L do Result := Result +(Pos(s[L-I+1],DD) - 1) * IntPower(jz,i - 1); end;