from functools import reduce


def _extract(key, start, length):
    """Extract a bitstring(2.x)/bytestring(2.x) from a string of binary digits, and return its
    numeric value."""
    k=key[start:start+length]
    return reduce(lambda x,y: x*2+ord(y)-48, k, 0)