aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/utils/bits.py
blob: 2c89a999b24dc73902c1f48398ff72558f792b2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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)