I need to be able to put 0x56 into a variable, but for some reason I can only find things on converting Hex into integers etc.
-
2Data types are not hexadecimal they store just numbers. For printing numbers usually uses the decimal format but in code you directly assign hexadecimal values by using e.g. $56 – Robert Nov 28 '20 at 23:04
Hex notation is just a way to represent a number. See Numerals.
In Delphi you can assign hex values to a number by using the $
prefix.
A text string can also be converted to a number using a 0x
prefix. SysUtils.StrToInt
Se the example program below to get a grip of it:
program Project174;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
var
X: Integer;
begin
x := $56; // Hex notation (base 16)
WriteLn(x); // Writes 86
x := StrToInt('0x56');
WriteLn(x); // Writes 86
x := StrToInt('$56');
WriteLn(x); // Writes 86
X := 86; // Decimal notation (base 10)
WriteLn(X); // Writes 86
ReadLn;
end.
-
If he want character ‘56’ or ‘0x56’ then you can prefix the ‘number’ with a #. Ex
#56
or#$56
– R. Hoek Nov 29 '20 at 8:21