Tutorials to .com

Tutorials to .com » Software » Delphi » IntToHex (10-16 hex conversion)

IntToHex (10-16 hex conversion)

Print View , by: iSee ,Total views: 44 ,Word Count: 274 ,Date: Mon, 24 Aug 2009 Time: 4:09 AM


10-2 hex conversion of that process, I am glad that many friends have provided a concise than I want a good way, this is to see a friend's BLOG, the written conversion of 10-16 from the start I was also was wrong, Oh, will now remain in the correct blog, he asked to write their own conversion, rather than using a similar
Format ( 'Integer% 0: d in Hex is% 0: .8 x', [Value]);
Of course, there are simple way we have to use simple way oh Then introduced their own methods
var HexArr: array [1 .. 15] of string = ('1 ', '2', '3 ', '4', '5 ', '6', '7 ', '8', '9 ', 'A', 'B', 'C', 'D', 'E', 'F');

function Int2Hex (Value: Integer): string;
var
iTemp: Integer;
i: Integer;
begin
Result: ='';
i: = 0;
while i <4 do
begin
case i of
0: iTemp: = Value shr 24 and $ FF;
1: iTemp: = Value shr 16 and $ FF;
2: iTemp: = Value shr 8 and $ FF;
3: iTemp: = Value and $ FF;
end;
if not Boolean (iTemp) then Result: = Result + '00 '
else begin
Result: = Result + HexArr [iTemp div 16];
Result: = Result + HexArr [iTemp mod 16];
end;
Inc (i);
end;
end;

Test: ShowMessage (Int2Hex (-1)); / / display FFFFFFFF
ShowMessage (Int2Hex (MAXINT)); / / display 7FFFFFFF

Hope that more suggestions, and personally feel quite concise, and Oh, obviously what it is doing each step


Delphi Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.