?? data.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字轉變?yōu)閁UT能識別的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 + -