def build_tos(
    precedence: int, lowdelay: bool, throughput: bool, reliability: bool, lowcost: bool
) -> int:
    """Building IP Type of Service value

    Args:
        precedence (int): intended to denote the importance or priority of the datagram
            0b1000   --   minimize delay
            0b0100   --   maximize throughput
            0b0010   --   maximize reliability
            0b0001   --   minimize monetary cost
            0b0000   --   normal service
        lowdelay (bool): low (True), normal (False)
        throughput (bool): high (True) or low (False)
        reliability (bool): high (True) or normal (False)
        lowcost (bool): minimize memory cost (True)

    Returns:
        int: type of service as describe in the RFC 1349 and 791
    """
    return (
        (lowcost << 1)
        + (reliability << 2)
        + (throughput << 3)
        + (lowdelay << 4)
        + (max(min(precedence, 0b111), 0b000) << 5)
    )