there may be some errors in the code but generally it should work. Value is the 32 bit combination that you are working with, Bit is the order of the bit that you want to read/change.Code:function GetBit(const Value, Bit: LongWord): Boolean; begin Result := Boolean((Value shr Bit) and 1); end; function SetBit(const Value, Bit: LongWord; const NewBitValue: Boolean): LongWord; beign Result := (Value and not LongWord(1 shl Bit)) or (LongWord(NewBitValue) shl Bit) end;
However, in pascal there is a more convenient way of working with bit flags - sets. they are very neatly designed, support up to 128 bits and compile into the same optimized binary math.
Bookmarks