set or clear a bit without branching
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
Comments
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎