def _leading_zeros(value, bit_width=8):
    """Count leading zeros on a binary number with a given bit_width

    ie: 0b0011 = 2

    Used for shifting around values after masking.
    """
    count = 0
    for _ in range(bit_width):
        if value & (1 << (bit_width - 1)):
            return count
        count += 1
        value <<= 1
    return count