[fpc-pascal] Bit manipulation helpers

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Feb 21 13:53:10 CET 2022


On Mon, 21 Feb 2022 13:34:29 +0100
gabor via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:

> W dniu 2022-02-21 o 13:18, Ryan Joseph via fpc-pascal pisze:
> > 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;  
> 
> Should you use the "AND" operator instead of "OR" for bit testing?
> 
> result := Value = (Value AND Index);

No.

result := (Byte(Value) AND Index)>0;

result := Index = (Byte(Value) AND Index);

result := Byte(Value) = (Byte(Value) OR Index);

Mattias


More information about the fpc-pascal mailing list