[fpc-pascal] Bit manipulation helpers

Ryan Joseph genericptr at gmail.com
Mon Feb 21 13:18:57 CET 2022



> On Feb 21, 2022, at 7:01 PM, Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> Yes, this is testbit.
> 
> Why do you say it does not work ?

Oh my, I was confusing my terms I think. I wanted to do bit masking (I think it's called). I was expecting there to be something like TestFlag in the RTL since I can never remember the syntax "Value = (Value or Index)"
 
function TestFlag(Value: QWord; Index: Byte): Boolean;
begin
  result := Value = (Value or Index);
end;

const
  KMOD_LCTRL = $0040;
  KMOD_RCTRL = $0080;

var
  flags: LongWord;
begin
  flags := KMOD_LCTRL + KMOD_RCTRL;
  writeln('TestBit: ', flags.TestBit(KMOD_LCTRL));
  writeln('TestFlag: ', TestFlag(flags, KMOD_LCTRL));


Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list