RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.IntToHex Function

Returns the hex representation of an integer.

Pascal
function IntToHex(Value: Integer; Digits: Integer): string; overload;
function IntToHex(Value: Int64; Digits: Integer): string; overload;
C++
AnsiString IntToHex(int Value, int Digits);
AnsiString IntToHex(Int64 Value, int Digits);

IntToHex converts a number into a string containing the number's hexadecimal (base 16) representation. Value is the number to convert. Digits indicates the minimum number of hexadecimal digits to return.  

C++ Examples: 

 

/*
The following example uses an edit control, a button, and a
label on a form. When the button is clicked, the hexadecimal
value of each character in the edit control is displayed in
the label.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Label1->Caption = "";
  for (int i = 1; i <= Edit1->Text.Length(); i++)
  {
    try
    {
      Label1->Caption =
        Label1->Caption +
        IntToHex(Byte(Edit1->Text[i]),2) + ' ';
    }
    catch (...)
    {
      Beep();
    }
  }
}

 

Delphi Examples: 

{
The following example uses an edit control, a button, and a
label on a form. When the button is clicked, the hexadecimal
value of each character in the edit control is displayed in
the label.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  Label1.Caption := '';
  for i := 1 to Length(Edit1.Text) do
  begin
    try
      Label1.Caption :=
        Label1.Caption +
        SysUtils.IntToHex(Byte(Edit1.Text[i]),2) + ' ';
    except
      Beep;
    end;
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!