def _extract_8_bits(long_value, shift=1):
    """Return an integer in the range 0, 255 by extracting 8 bits from the
    input long value. shift determines which 8 bits are taken, by default
    the first 8 bits."""

    bitmask = (1 << 8 * shift) - 1

    return (long_value & bitmask) >> (8 * (shift-1))