⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 data.txt

📁 几种进制转换的程序,在DELPHI使用。
💻 TXT
字号:
//十六进制(S)-->>十进制(I)
function hextoint(s: string): Integer;
begin       
  Result:=StrToInt('$'+s);
end;

//十进制转换为二进制字符串
function inttoBin(i: integer): string;
begin
 while i <>0 do
 begin       
   result:=Format('%d'+result,[i mod 2]);
   i:=i div 2
 end
end;

//二进制(S)-->>十进制(D) 
uses Math; 
function hextoint(s: string): Double;
begin
  while Length(s) <>0 do
  begin  
    if s[1]='1' then  Result:=Result+power(2,Length(s)-1);
    s:=Copy(s,2,Length(s));
  end
end;

//十进制(I)-->>十六进制(S)

function IntToHex(Value: Integer; Digits: Integer): string;


//数据(S)-->>二进制(S) 

function conertde(s:string):string; 
var 
 i:integer; 
begin 
 for i:=1 to length(s) do 
   result:=result+inttohex(ord(s[i]),2); 
end;
///////////////////////////////////////////////////////////////////////////////
function HextoInt(HexStr: String): Integer;
var
i: Integer;
begin
Result := 0;
   for i := 1 to Length(HexStr) do
      begin
           case HexStr[i] of
                '0'..'9' : Result := Result * 16 + StrToInt(HexStr[i]);
                'a', 'A' : Result := Result * 16 + 10;
                'b', 'B' : Result := Result * 16 + 11;
                'c', 'C' : Result := Result * 16 + 12;
                'd', 'D' : Result := Result * 16 + 13;
                'e', 'E' : Result := Result * 16 + 14;
                'f', 'F' : Result := Result * 16 + 15;
            end;
   end;
end;
/////////////////////////////////////////////////////////////////////////////////
function Hextobcd(hexstr:string):string;
var
i:integer;
begin
Result := '';
for i:=1 to Length(hexstr) do
    begin
         case hexstr[i] of
              '0':Result:=Result+'0000';
              '1':Result:=Result+'0001';
              '2':Result:=Result+'0010';
              '3':Result:=Result+'0011';
              '4':Result:=Result+'0100';
              '5':Result:=Result+'0101';
              '6':Result:=Result+'0110';
              '7':Result:=Result+'0111';
              '8':Result:=Result+'1000';
              '9':Result:=Result+'1001';
              'A','a':Result:=Result+'1010';
              'B','b':Result:=Result+'1011';
              'C','c':Result:=Result+'1100';
              'D','d':Result:=Result+'1101';
              'E','e':Result:=Result+'1110';
              'F','f':Result:=Result+'1111';
          end;
   end;
end;
///////////////////////////////////////////////////////////////////////////////
function xchange(bstr:string):string;
var
i,j:integer;
temp:string;
begin
temp:=bstr;
j:=0;
Result:='';
for i:=1 to length(bstr) do
    if (i<length(bstr)/2) then
        begin
        bstr[i]:=bstr[length(bstr)-j];
        result:=result+bstr[i];
        j:=j+1;
        end
        else
        begin
        bstr[i]:=temp[length(temp)-j];
        result:=result+bstr[i];
        j:=j+1;
    end;
end;
///////////////////////////////////////////////////////////////////////////////
function Btoo(bstr:string):string;
var
i,j:integer;
temp,temp1:string;
begin
temp1:='0'+bstr;
Result:='';
i:=1;
j:=1;
    while (i<=length(temp1)/3)  do
          begin
             temp:=copy(temp1,j,3);
                   case strtoint(temp) of
                        000:Result:=Result+'0';
                        001:Result:=Result+'1';
                        010:Result:=Result+'2';
                        011:Result:=Result+'3';
                        100:Result:=Result+'4';
                        101:Result:=Result+'5';
                        110:Result:=Result+'6';
                        111:Result:=Result+'7';
                    end;
             j:=j+3;
             i:=i+1;
           end;
end;
///////////////////////////////////////////////////////////////////////////////
function Bcdtohex(bstr:string):string;
var
i,j:integer;
temp,temp1:string;
begin
temp1:=bstr;
Result:='';
i:=1;
j:=1;
    while (i<=length(temp1)/4)  do
          begin
             temp:=copy(temp1,j,4);
                   case strtoint(temp) of
                        0000:Result:=Result+'0';
                        0001:Result:=Result+'1';
                        0010:Result:=Result+'2';
                        0011:Result:=Result+'3';
                        0100:Result:=Result+'4';
                        0101:Result:=Result+'5';
                        0110:Result:=Result+'6';
                        0111:Result:=Result+'7';
                        1000:Result:=Result+'8';
                        1001:Result:=Result+'9';
                        1010:Result:=Result+'A';
                        1011:Result:=Result+'B';
                        1100:Result:=Result+'C';
                        1101:Result:=Result+'D';
                        1110:Result:=Result+'E';
                        1111:Result:=Result+'F';
                    end;
             j:=j+4;
             i:=i+1;
           end;
end;

///////////////////////////////////////////
function BinToInt(Value: string): Integer;
var i, iValueSize: Integer;
begin
    Result := 0;
    iValueSize := Length(Value);
    for i := iValueSize downto 1 do
    if Value[i] = '1' then Result := Result + (1 shl (iValueSize - i));
end; 

function HextoInt(HexStr: String): Integer; export;
var
i: Integer;
begin
Result := 0;
   for i := 1 to Length(HexStr) do
      begin
           case HexStr[i] of
                '0'..'9' : Result := Result * 16 + StrToInt(HexStr[i]);
                'a', 'A' : Result := Result * 16 + 10;
                'b', 'B' : Result := Result * 16 + 11;
                'c', 'C' : Result := Result * 16 + 12;
                'd', 'D' : Result := Result * 16 + 13;
                'e', 'E' : Result := Result * 16 + 14;
                'f', 'F' : Result := Result * 16 + 15;
            end;
   end;
end;
//////////////////////////////////////////////////////////
//十六进制转BCD码
function Hextobcd(hexstr:string):string; export;
var
i:integer;
begin
Result := '';
for i:=1 to Length(hexstr) do
    begin
         case hexstr[i] of
              '0':Result:=Result+'0000';
              '1':Result:=Result+'0001';
              '2':Result:=Result+'0010';
              '3':Result:=Result+'0011';
              '4':Result:=Result+'0100';
              '5':Result:=Result+'0101';
              '6':Result:=Result+'0110';
              '7':Result:=Result+'0111';
              '8':Result:=Result+'1000';
              '9':Result:=Result+'1001';
              'A','a':Result:=Result+'1010';
              'B','b':Result:=Result+'1011';
              'C','c':Result:=Result+'1100';
              'D','d':Result:=Result+'1101';
              'E','e':Result:=Result+'1110';
              'F','f':Result:=Result+'1111';
          end;
   end;
end;
///////////////////////////////////////////////////////////
//字符串交换
function xchange(bstr:string):string;  export;
var
i,j:integer;
temp:string;
begin
temp:=bstr;
j:=0;
Result:='';
for i:=1 to length(bstr) do
    if (i<length(bstr)/2) then
        begin
        bstr[i]:=bstr[length(bstr)-j];
        result:=result+bstr[i];
        j:=j+1;
        end
        else
        begin
        bstr[i]:=temp[length(temp)-j];
        result:=result+bstr[i];
        j:=j+1;
    end;
end;
//////////////////////////////////////////////////////////////
//二进制转八进制
function Btoo(bstr:string):string; export;
var
i,j:integer;
temp,temp1:string;
begin
temp1:='0'+bstr;
Result:='';
i:=1;
j:=1;
    while (i<=length(temp1)/3)  do
          begin
             temp:=copy(temp1,j,3);
                   case strtoint(temp) of
                        000:Result:=Result+'0';
                        001:Result:=Result+'1';
                        010:Result:=Result+'2';
                        011:Result:=Result+'3';
                        100:Result:=Result+'4';
                        101:Result:=Result+'5';
                        110:Result:=Result+'6';
                        111:Result:=Result+'7';
                    end;
             j:=j+3;
             i:=i+1;
           end;
end;
//////////////////////////////////////////////////////////////
//二进制转十六进制
function Bcdtohex(bstr:string):string; export;
var
i,j:integer;
temp,temp1:string;
begin
temp1:='0'+bstr;
Result:='';
i:=1;
j:=1;
    while (i<=length(temp1)/4)  do
          begin
             temp:=copy(temp1,j,4);
                   case strtoint(temp) of
                        0000:Result:=Result+'0';
                        0001:Result:=Result+'1';
                        0010:Result:=Result+'2';
                        0011:Result:=Result+'3';
                        0100:Result:=Result+'4';
                        0101:Result:=Result+'5';
                        0110:Result:=Result+'6';
                        0111:Result:=Result+'7';
                        1000:Result:=Result+'8';
                        1001:Result:=Result+'9';
                        1010:Result:=Result+'A';
                        1011:Result:=Result+'B';
                        1100:Result:=Result+'C';
                        1101:Result:=Result+'D';
                        1110:Result:=Result+'E';
                        1111:Result:=Result+'F';
                    end;
             j:=j+4;
             i:=i+1;
           end;
end;
//////////////////////////////////////////////////////////////
//将ARINC429字转变为UUT能识别的429字
function Arinctouut(arincdata:string):string; export;
var
arinctemp:string;
begin
arinctemp:=Hextobcd(arincdata);
arinctemp:=copy(arinctemp,4,16)+copy(arinctemp,20,5)+copy(arinctemp,2,2)+copy(arinctemp,1,1)+copy(arinctemp,25,8);
Result:=bcdtohex(arinctemp);
end;
//////////////////////////////////////////////////////////////
//将UUT字转变ARINC429
function Uuttoarinc(uutdata:string):string; export;
var
uutdatatemp:string;
begin
uutdatatemp:=hextobcd(uutdata);
uutdatatemp:=copy(uutdata,24,1)+copy(uutdata,22,2)+copy(uutdata,1,21)+copy(uutdata,25,8);
result:=bcdtohex(uutdatatemp);
///////////////////////////////////////////////////////////////
//十六进制转十进制
function Hex_Int(HexStr: String): Integer;
var
i: Integer;
begin
Result := 0;
   for i := 1 to Length(HexStr) do
      begin
           case HexStr[i] of
                '0'..'9' : Result := Result * 16 + StrToInt(HexStr[i]);
                'a', 'A' : Result := Result * 16 + 10;
                'b', 'B' : Result := Result * 16 + 11;
                'c', 'C' : Result := Result * 16 + 12;
                'd', 'D' : Result := Result * 16 + 13;
                'e', 'E' : Result := Result * 16 + 14;
                'f', 'F' : Result := Result * 16 + 15;
            end;
   end;
end;
///////////////////////////////////////////////////////////////////
//十六进制转BCD码(BCB之间采用空格隔开)
function hextobcd(hexstr:string):string;
var
i:integer;
begin
Result := '';
for i:=1 to Length(hexstr) do
    begin
         case str[i] of
              '0':Result:=Result+'0000'+#20;
              '1':Result:=Result+'0001'+#20;
              '2':Result:=Result+'0010'+#20;
              '3':Result:=Result+'0011'+#20;
              '4':Result:=Result+'0100'+#20;
              '5':Result:=Result+'0101'+#20;
              '6':Result:=Result+'0110'+#20;
              '7':Result:=Result+'0111'+#20;
              '8':Result:=Result+'1000'+#20;
              '9':Result:=Result+'1001'+#20;
              'A','a':Result:=Result+'1010'+#20;
              'B','b':Result:=Result+'1011'+#20;
              'C','c':Result:=Result+'1100'+#20;
              'D','d':Result:=Result+'1101'+#20;
              'E','e':Result:=Result+'1110'+#20;
              'F','f':Result:=Result+'1111'+#20;
          end;
   end;
end;
///////////////////////////////////////////////////////////
//字符串交换
function xchange(bstr:string):string;
var
i,j:integer;
temp:string;
begin
temp:=bstr;
j:=0;
Result:='';
for i:=1 to length(bstr) do
    if (i<length(bstr)/2) then
        begin
        bstr[i]:=bstr[length(bstr)-j];
        result:=result+bstr[i];
        j:=j+1;
        end
        else
        begin
        bstr[i]:=temp[length(temp)-j];
        result:=result+bstr[i];
        j:=j+1;
    end;
end;
//////////////////////////////////////////////////////////////
//二进制转八进制
function bintolable(bstr:string):string;
var
i,j:integer;
temp,temp1:string;
begin
temp1:='0'+bstr;
Result:='';
i:=1;
j:=1;
    while (i<=length(temp1)/3)  do
          begin
             temp:=copy(temp1,j,3);
                   case strtoint(temp) of
                        000:Result:=Result+'0';
                        001:Result:=Result+'1';
                        010:Result:=Result+'2';
                        011:Result:=Result+'3';
                        100:Result:=Result+'4';
                        101:Result:=Result+'5';
                        110:Result:=Result+'6';
                        111:Result:=Result+'7';
                    end;
             j:=j+3;
             i:=i+1;
           end;
end;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -