2019-05-15 16:36:32 +00:00
|
|
|
def set_bitfield_bit(bitfield, i):
|
|
|
|
"""
|
|
|
|
Set the bit in ``bitfield`` at position ``i`` to ``1``.
|
|
|
|
"""
|
|
|
|
byte_index = i // 8
|
|
|
|
bit_index = i % 8
|
|
|
|
return (
|
2019-06-01 00:40:29 +00:00
|
|
|
bitfield[:byte_index] +
|
|
|
|
bytes([bitfield[byte_index] | (1 << bit_index)]) +
|
|
|
|
bitfield[byte_index + 1:]
|
2019-05-15 16:36:32 +00:00
|
|
|
)
|