1.函数原型:
{ IntToHex converts the given value to a hexadecimal string representation
with the minimum number of digits specified. }
function IntToHex(Value: Integer; Digits: Integer): string; overload;
function IntToHex(Value: Int64; Digits: Integer): string; overload;
2.函数功能:将10进制整数转换为十六进制数
参数含义: Value: 要转换的数字;Digists:转换后的位数。
3.函数实现
function IntToHex(Value: Integer; Digits: Integer): string;
// FmtStr(Result, '%.*x', [Digits, Value]);
asm
CMP EDX, 32 // Digits < buffer length?
JBE @A1
XOR EDX, EDX
@A1: PUSH ESI
MOV ESI, ESP
SUB ESP, 32
PUSH ECX // result ptr
MOV ECX, 16 // base 16 EDX = Digits = field width
CALL CvtInt
MOV EDX, ESI
POP EAX // result ptr
CALL System.@LStrFromPCharLen
ADD ESP, 32
POP ESI
end;
function IntToHex(Value: Int64; Digits: Integer): string;
// FmtStr(Result, '%.*x', [Digits, Value]);
asm
CMP EAX, 32 // Digits < buffer length?
JLE @A1
XOR EAX, EAX
@A1: PUSH ESI
MOV ESI, ESP
SUB ESP, 32 // 32 chars
MOV ECX, 16 // base 16
PUSH EDX // result ptr
MOV EDX, EAX // zero filled field width: 0 for no leading zeros
LEA EAX, Value;
CALL CvtInt64
MOV EDX, ESI
POP EAX // result ptr
CALL System.@LStrFromPCharLen
ADD ESP, 32
POP ESI
end;
//有时间研究下汇编指令。(*^__^*) 嘻嘻……大家谁有时间研究好了可以回帖给我哦