想要写一个function,将输入的33进制字符串输出为10进制。
33进制字符串'0123456789ACDEFGHJKLMNPQRSTUVWXYZ'
想要写一个function,将输入的33进制字符串输出为10进制。
33进制字符串'0123456789ACDEFGHJKLMNPQRSTUVWXYZ'
unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class
()
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label1: TLabel;
Label2: TLabel;
procedure
Button1Click(Sender: TObject);
procedure
Button2Click(Sender: TObject);
procedure
Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end
;
var
Form1: TForm1;
implementation
{
$R
*.dfm}
const
// ACIIS表 由字符对应数字
Convert:
array
[
0..255
]
of
Integer
=
(-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
33
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,-
1
,
18
,
19
,
20
,
21
,
22
,-
1
,
23
,
24
,
25
,
26
,
27
,-
1
,
28
,
29
,
30
,
31
,
32
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,-
1
,
18
,
19
,
20
,
21
,
22
,-
1
,
23
,
24
,
25
,
26
,
27
,-
1
,
28
,
29
,
30
,
31
,
32
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,
-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
,-
1
);
// 数字(下标)对应字符
Convert2:
array
[
0..33
]
of
AnsiChar
=
(
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
,
'G'
,
'H'
,
'J'
,
'K'
,
'L'
,
'M'
,
'N'
,
'P'
,
'Q'
,
'R'
,
'S'
,
'T'
,
'V'
,
'W'
,
'X'
,
'Y'
,
'Z'
,
'0'
);
function
IntToHEX33(
const
V:
Int64
;
const
Digits:
Integer
= -
1
):
string
;
const
CSTR =
'0000000000000000'
;
var
P, P1:
PAnsiChar
;
I:
Int64
;
NewLen:
Integer
;
begin
GetMem(P,
16
);
Move(CSTR, P^,
16
);
P1 := P +
16
-
1
;
I := V;
while
True
do
begin
P1^ := Convert2[I
mod
33
];
I := I
div
33
;
if
I =
0
then
Break
else
Dec(P1);
end
;
NewLen :=
16
- (P1 - P);
if
NewLen > Digits
then
SetString(Result, P1, NewLen)
else
begin
P1 := P +
16
- Digits;
SetString(Result, P1, Digits);
end
;
end
;
function
HEX33ToInt(
const
S:
string
;
const
Default:
Int64
):
Int64
;
var
I:
Integer
;
v:
Int64
;
begin
Result :=
0
;
for
I :=
1
to
length(s)
do
begin
V := Convert[ord(s[i])];
if
V <
0
then
begin
Result := Default;
Exit;
end
;
result := (result *
33
) + V;
end
;
end
;
procedure
TForm1
.
Button1Click(Sender: TObject);
begin
Edit2
.
Text := IntToHEX33(StrToInt64Def(Edit1
.
Text,
0
));
end
;
procedure
TForm1
.
Button2Click(Sender: TObject);
begin
Edit1
.
Text := IntToStr(HEX33ToInt(Edit2
.
Text,
0
));
end
;
procedure
TForm1
.
Button3Click(Sender: TObject);
begin
close;
end
;
end
.