소프트웨어개발/Delphi
[Delphi] Int -> Hex / Hex -> Int 변환
곽코딩
2017. 10. 27. 16:49
반응형
설명은 따로 없습니다. 아래 코드를 참고하세요.
const
HexChars: array[0..15] of Char = ('0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b',
'c', 'd', 'e', 'f');
function IntToHex(Int: Int64; IntSize: Byte): string;
var
n: Byte;
begin
Result := '';
for n := 0 to IntSize - 1 do
begin
Result := HexChars[Int and $F] + Result;
Int := Int shr $4;
end;
end;
function HexToInt(const Value: string): LongWord;
const
HexStr: String = '0123456789abcdef';
var
i: Word;
begin
Result := 0;
if Value = '' then Exit;
for i := 1 to Length(Value) do
Inc(Result, (Pos(Value[i], HexStr) - 1) shl ((Length(Value) - i) shl 2));
end;