10进制数与33进制数的转换
来源:互联网 发布:淘宝直通车创意是什么 编辑:程序博客网 时间:2024/06/11 05:42
10进制数与33进制数的转换
CSDN论坛,有人提出“10进制数与33进制数的转换”,参考网上资料,经修改,得出代码及心得如下:
一、33进制数格式
33进制数序列为: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
注意字母:I、O、U不用。
二、转换的机制
1、建立一个ASCII码的对应表(数组),它的下标是ASCII的序列值。数组值是33进制的值。33进制转换10进制时,靠该表由字符对应查询到数值。
2、建立一个33进制数序列表(数组),它的下标对应33进制数值,数组值是33进制字符。10进制转换33进制时,靠该表由1-33数值对应查询到字符。
三、实现代码如下:
unit Unit1;
interface
uses
Windows, Messages,SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;
Type
TForm1 = class(TForm)
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; constDigits: 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; constDefault: 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.
四、界面
- 10进制数与33进制数的转换
- char*与16进制数转换
- HDOJ/HDU 2352 Verdis Quo(罗马数字与10进制数的转换)
- 与、的数据转换
- 任意进制数的转换
- 进制数的转换
- 进制数之间的转换
- Java汉字与16进制数相互转换
- Java汉字与16进制数相互转换
- 16进制数与字符串转换函数
- 16进制数与浮点数转换
- AD转换与DA转换的应用
- Java数据类型的转换:隐式(自动)转换与强制转换
- 十进制与十六进制的转换,二进制与十六进制的转换
- 字符串与数组的转换
- 字符串与数组的转换
- 字符串与ascii的转换
- WCHAR与CHAR的转换
- uvm_object的理解
- Android Studio 关联GitHub相关操作
- AbstractQueuedSynchronizer的介绍和原理分析
- [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: entity.NewsBean
- C++运算符重载例子代码
- 10进制数与33进制数的转换
- 【DENUVO】一代天子一代臣,这代好像有点“颓”?
- JVM学习 - 体系结构 内存模型
- Android 图案解锁
- BZOJ3244: [Noi2013]树的计数
- 面向对象介绍
- CPU缓存刷新的误解
- 深入JVM锁机制-Lock
- Android电话拨号器