十六进制字符串显示问题 (20分)

  • 主题发起人 hnliujin
  • 开始时间
H

hnliujin

Unregistered / Unconfirmed
GUEST, unregistred user!
要求在一memo中将十进制数转化为十六进制显示如十进制10显示为A,255显示为FF
 

IntToHex()

在onKeydown里判断 if key in ['0'..'9'] then
 
memo1.Lines.Add(IntToHex(StrToInt('12345')));
 
to youngsun:
没这么简单吧好像两个类型就不一样.inttohex这个函数我当然晓得.]

编绎结果是:There is no overloaded version of 'IntToHex' that can be
called with these arguments
 
IntToHex(StrToInt('12345'),4);
 
两个参数
inttohex(value,digits);
 
嘿嘿……楼上的语句编译有错!
memo1.Lines.Add(IntToHex(StrToInt(Edit1.Text),0));
 
是不是每个字节转换。
inttohex(ord(s),2)
 
嘿嘿,确实是我的错,少写了一个参数,现丑现丑。
 
散分了原来inttohex返回的是Tsting.下次要多看看源代码了
 
var
number:integer;
hexnumber: string;
begin
number := 100;

hexnumber := inttohex(number,2);

//hexnumber 显示为 64 (100的16进制);
end;
 
function BufferToHex(Buffer: Pointer; Count: Integer): string;
var
tmpPChar : PChar;
HexStr : string;
i : Integer;
begin
Result := '';
tmpPChar := Buffer;
for i := 0 to Count - 1 do
begin
HexStr := IntToHex(Ord(tmpPChar^), 2);
Result := Result + HexStr;
inc(tmpPChar);
end;
end;
这样使用
var
str:string;
...
str:=memo1.text;
memo1.text:=BufferToHex(str[1],length(str));
 
接受答案了.
 
顶部