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;
任意进制(2-36内)与十进制间的转换
最新推荐文章于 2021-01-27 13:41:14 发布
本文介绍了两个用于不同进制间转换的函数:DecimalToStr 和 StrToDecimal。前者将十进制整数转换为指定进制的字符串形式,后者则完成相反的过程,即从指定进制的字符串中解析出其对应的十进制整数值。文章提供了完整的函数实现代码,并解释了其中涉及的算法思想。

5331

被折叠的 条评论
为什么被折叠?



