function StrtoHex(S: String; AFormat: Integer;formatstring : String): String;
var
I : Integer ;
Temp : String ;
begin
Temp := '';
if s = '' then StrtoHex := '' else
begin
For I := 1 to Length(s) do
begin
temp := Temp + formatstring +InttoHex(Ord(s[i]),Aformat);
end ;
end ;
Strtohex := temp ;
end;
var
I : Integer ;
Temp : String ;
begin
Temp := '';
if s = '' then StrtoHex := '' else
begin
For I := 1 to Length(s) do
begin
temp := Temp + formatstring +InttoHex(Ord(s[i]),Aformat);
end ;
end ;
Strtohex := temp ;
end;
begin
??????????????????
end;
HELP ME...
StrtoHex (s,2,'0X');则为‘0X310X320X330X34’
StrtoHex (s,3,'');则为‘031032033034’
begin
??????????????????
end;
__________________
什么意思?将字符串转换成Byte?ord():返回一个字符的ASCII值(整数)
Inttohex:将整形的16进制返回为字符串
function StrToByte(A:char):byte呀
好办了
function StrToByte(A:char):byte
begin
StrToByte := strtoint(InttoHex(Ord(c),2));
end ;
function StrToByte(A:char):byte
begin
StrToByte := strtoint(InttoHex(Ord(A),2));
end ;
function HexToDec(HexData: Integer): Integer;
var m: Integer;
begin
Result := 0;
m := Trunc(Power(10, Length(IntToStr(HexData)) - 1));
while m > 0 do
begin
Result := (Result*16 + HexData div m);
HexData := HexData mod m;
m := m div 10;
end;
end;function DecToHex(DecData: Integer): Integer;
var m: Integer;
begin
Result := 0;
m := Trunc(Power(16, Length(IntToStr(DecData)) - 1));
while m > 0 do
begin
Result := (Result*10 + DecData div m);
DecData := DecData mod m;
m := m div 16;
end;
end;
//将十六进制的字符串转成整型
//判断是否是十六进制数
function IsHexChar(Chr: char): boolean;
begin
Result := (Chr in ['0'..'9']) or (Chr in ['A'..'F']);
end;
//将一个十六进制字符转换成数
function HexChrtoInt(Chr: char): byte;
begin
Result := 0;
case Chr of
'0'..'9' : Result := Strtoint(Chr);
'A' : Result := 10;
'B' : Result := 11;
'C' : Result := 12;
'D' : Result := 13;
'E' : Result := 14;
'F' : Result := 15;
end;
end;
var
BufLength: dword;
TempBuf: string;
Count0: dword;
begin
Result := 0;
BufLength := Length(Buf);
TempBuf := '';
if BufLength > 0 then begin
Buf := Uppercase(Buf);
// for Count0 := 1 to BufLength
if BufLength mod 2 = 1 then begin
Buf := '0' + Buf;
BufLength := Length(Buf);
end;
for Count0 := 1 to BufLength div 2 do
if IsHexChar(Buf[Count0 * 2 - 1]) then begin
if IsHexChar(Buf[Count0 * 2]) then begin
TempBuf := TempBuf + inttostr(HexChrtoInt(Buf[Count0 * 2 - 1]) * 16 + HexChrtoInt(Buf[Count0 * 2]));
end else begin
Result := Count0 * 2;
Break;
end;
end else begin
Result := Count0 * 2 - 1;
Break;
end;
if Result = 0 then Buf := TempBuf;
end;
end;
这么简单,还不试试!