def encode_multi_byte_int(value: int) -> bytes:
    """Encode an unsigned integer into up to 5 bytes

    :param value: The unsigned integer to encode
    :return: A byte string encoding the given integer
    """
    if value > 2147483647 or value < 0:
        raise ValueError("Can not encode integer of more than 31 bits")

    b5 = ((value >> 28) & 0x03)
    b4 = ((value >> 21) & 0x7F) | (0x80 if b5 > 0 else 0)
    b3 = ((value >> 14) & 0x7F) | (0x80 if b4 > 0 else 0)
    b2 = ((value >> 7) & 0x7F) | (0x80 if b3 > 0 else 0)
    b1 = (value & 0x7F) | (0x80 if b2 > 0 else 0)
    if b5 > 0:
        return bytes((b1, b2, b3, b4, b5))
    if b4 > 0:
        return bytes((b1, b2, b3, b4))
    if b3 > 0:
        return bytes((b1, b2, b3))
    if b2 > 0:
        return bytes((b1, b2))
    return bytes((b1, ))