在Delphi 2010中将十六进制字符串转换为ansistring
发布时间:2020-12-15 09:19:19 所属栏目:大数据 来源:网络整理
导读:我曾经使用这个函数将十六进制字符串转换为Delphi 6中的字符串: consttestSign = '207F8060287F585054505357FFD55861';function Hex2Dec(const data: string): byte;var nH1,nH2: byte;begin if data[1] in ['0' .. '9'] then nH1 := strtoint(data[1]) els
我曾经使用这个函数将十六进制字符串转换为Delphi 6中的字符串:
const testSign = '207F8060287F585054505357FFD55861'; function Hex2Dec(const data: string): byte; var nH1,nH2: byte; begin if data[1] in ['0' .. '9'] then nH1 := strtoint(data[1]) else nH1 := 9 + ord(data[1]) - 64; if data[2] in ['0' .. '9'] then nH2 := strtoint(data[2]) else nH2 := 9 + ord(data[2]) - 64; Result := nH1 * 16 + nH2; end; function HexStrToStr(const HexStr: string): string; var BufStr: string; LenHex: Integer; x,y: Integer; begin LenHex := Length(HexStr) div 2; x := 1; y := 0; while y <> LenHex do begin Inc(y); BufStr := BufStr + Chr(Hex2Dec(HexStr[x] + HexStr[x + 1])); Inc(x,2); end; Result := BufStr; end; 现在我想在Delphi 2010中使用该功能. const testSign: AnsiString = '207F8060287F585054505357FFD55861'; function Hex2Dec(const data: ansistring): byte; var nH1,nH2: byte; begin if data[1] in ['0' .. '9'] then nH1 := strtoint(data[1]) else nH1 := 9 + ord(data[1]) - 64; if data[2] in ['0' .. '9'] then nH2 := strtoint(data[2]) else nH2 := 9 + ord(data[2]) - 64; Result := nH1 * 16 + nH2; end; function HexStrToStr(const HexStr: ansistring): ansistring; var BufStr: ansistring; LenHex: Integer; x,2); end; Result := BufStr; end; D6中第一个代码的输出: ' '#$7F' |