Delphi hex string integer 32-bit decimal conversion

Delphi comes with a function IntToHex

Function Description: This function is used to convert the "decimal" to "hex." This function takes two parameters. The first argument to be converted to decimal data, the second argument is to specify how many bits to display hexadecimal data.

Reference Example:
  Edit1.Text: = INTTOHEX ( '100', 2);
  execution result, Edit1.Text equal to 64.

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;


  Note: Delphi does not provide special "Hex" to "decimal" function. StrToInt function can be achieved using this function. Specific codes are: I: = StrToInt ( '$' + '64'); I is equal to 100 at this time. That is coupled with a '$' to the "hex" to "decimal."

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
  J: Integer;
begin
  I := StrToInt(Edit1.Text);
  J := StrToInt(Edit2.Text);
  ShowMessage(IntToStr(I + J));
end;

// turn Decimal Hex
var
    I: Integer;
   STR: String;
the begin
    I: = 255;
    the ShowMessage (INTTOHEX (the I, 2)); // returns the number of bits of the FF 2 
// Further, Formart have the decimal hexadecimal output function
   STR: = the Format ( '.% 2x', [I]);
   the ShowMessage (STR); // return the result with the IntToStr the FF () function as like
End;
Delphi not provided hexadecimal converted to decimal function, but we can precede a decimal hexadecimal notation '$', then StrToInt () conversion


var
    STR: String;
    int: Integer;
the begin
    Str: = 'the FF';
    int: = StrToInt ( '$' + STR); 
    the ShowMessage (the IntToStr (int)); 255 //
End;

Guess you like

Origin blog.csdn.net/xyzhan/article/details/91414181