Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def set_bit(data: int, bit: int, value: bool):
- """
- Set or clear a bit of given data and return it.
- Look here: https://graphics.stanford.edu/~seander/bithacks.html#ConditionalSetOrClearBitsWithoutBranching
- """
- data ^= (-value ^ data) & (1 << bit)
- return data
Advertisement