国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

10進制數與33進制數的轉換

2019-11-10 20:21:33
字體:
來源:轉載
供稿:網友

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.

四、界面


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漾濞| 突泉县| 米易县| 珠海市| 嘉定区| 贵溪市| 衡山县| 潞城市| 铁岭县| 玛多县| 仙游县| 广安市| 庆元县| 潮安县| 边坝县| 宜兰市| 忻州市| 闸北区| 宜州市| 福安市| 天津市| 茌平县| 临安市| 赤水市| 桦甸市| 江安县| 台南市| 辽中县| 克拉玛依市| 盘锦市| 天津市| 加查县| 昭平县| 青田县| 鄂伦春自治旗| 上林县| 迁安市| 成武县| 易门县| 随州市| 钦州市|