mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-12-02 12:01:17 +00:00
72b753c60f
fixes #1848
14 lines
289 B
Python
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)
|