def get_bit(byte, n):
    """Extract a single bit from a byte, with 0 referring to
       the least significant (last) bit and 7 referring to the most
       significant (first) bit."""
    if type(byte) in [str, bytes]:
        if len(byte) != 1:
            raise ValueError('Expected a single byte')
        if type(byte) is str:
            byte = ord(byte)
        else:
            byte = byte[0]
    elif type(byte) is int:
        if byte < 0 or byte > 255:
            raise ValueError('Expected a value between 0 and 255')
    else:
        raise TypeError('Expected a character or integer')
    if n < 0 or n > 7:
        raise ValueError('n must be between 0 and 7')
    return byte >> n & 1
