import struct


def get_fctrl_up_byte(adr, adrackreq, ack, foptlen):
    """
    Returns the byte of the FCtrl field of FHDR.
    :param adr: bool (True/False)
    :param adrackreq: bool (True/False)
    :param ack: bool (True/False)
    :param foptlen: int. Length of the FOpts field of FHDR.
    :return: 1 byte.
    """
    assert 0 <= foptlen <= 15
    fctrl_int = foptlen
    if adr:
        fctrl_int |= 1 << 7
    if adrackreq:
        fctrl_int |= 1 << 6
    if ack:
        fctrl_int |= 1 << 5
    return struct.pack('B', fctrl_int)