Created
October 23, 2017 14:12
-
-
Save jonasraoni/0b868541c62050f3db539309678178a9 to your computer and use it in GitHub Desktop.
Functions to set/get bits on a DWord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GetBit(const Value: DWord; const Bit: Byte): Boolean; | |
begin | |
Result := (Value and (1 shl Bit)) <> 0; | |
end; | |
function EnableBit(const Value: DWord; const Bit: Byte; const TurnOn: Boolean): DWord; | |
begin | |
Result := (Value or (1 shl Bit)) xor (Integer(not TurnOn) shl Bit); | |
end; | |
function ClearBit(const Value: DWord; const Bit: Byte): DWord; | |
begin | |
Result := Value and not (1 shl Bit); | |
end; | |
function SetBit(const Value: DWord; const Bit: Byte): DWord; | |
begin | |
Result := Value or (1 shl Bit); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment