mitmproxy/mitmproxy/utils/bits.py
2017-01-19 20:27:29 +01:00

14 lines
289 B
Python

def setbit(byte, offset, value):
"""
Set a bit in a byte to 1 if value is truthy, 0 if not.
"""
if value:
return byte | (1 << offset)
else:
return byte & ~(1 << offset)
def getbit(byte, offset):
mask = 1 << offset
return bool(byte & mask)