Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define SmallInt constant as hexadecimal

Tags:

casting

delphi

I need to define a SmallInt constant with a hexadecimal value. In some way like this:

const
  a: SmallInt = $8000;

Of course, the $8000 value violates subrange bounds of SmallInt. I know it and do it deliberately. Actually, I need a bitwise transfer of this literal to 16-bit signed integer.

If it were a variable, I could use an absolute keyword:

var
  a_prototype: Word;
  a: SmallInt absolute a_prototype;
begin
  a_prototype := $8000;

but it should be a constant.

like image 965
Paul Avatar asked Jan 29 '20 08:01

Paul


1 Answers

Use a cast

const
  a = SmallInt($8000);

If you need a typed constant then it would be

const
  a: SmallInt = SmallInt($8000);
like image 165
David Heffernan Avatar answered Sep 18 '22 18:09

David Heffernan