This question may sound silly but I can not understand the idea behind the not
operator on constant integers. I get the following results:
not $FF
=>$FF00
not $FFFF
=>$FFFF0000
not $FFFFFFFF
=>$00
not $FFFFFFFFFFFFFFFF
=>$00
The first two values look wrong to me.
The documentation states:
For example, not performs bitwise negation on an integer operand
and later:
The result of a not operation is of the same type as the operand
This is not in line with the observed behaviour.
Full code example:
unit Unit5;
interface
procedure c();
implementation
uses Vcl.Dialogs, System.SysUtils;
procedure Invert(v: ShortInt); overload; begin
ShowMessage('ShortInt $' + v.ToHexString());
end;
procedure Invert(v: SmallInt); overload; begin
ShowMessage('SmallInt $' + v.ToHexString());
end;
procedure Invert(v: Integer); overload;
begin
ShowMessage('Integer $' + v.ToHexString());
end;
procedure c();
const
byteValue = not $FF; // = $FF00
wordValue = not $FFFF; // = $FFFF0000
cardValue = not $FFFFFFFF; // = $00
uint64Value = not $FFFFFFFFFFFFFFFF; // = $00
begin
Invert(byteValue);
Invert(wordValue);
Invert(cardValue);
Invert(uint64Value);
end;
end.