def int2bytearray(data, num_bytes):
    """Gets an integer and convert it to a byte array with specified number of bytes

    Args:
        data: integer
        num_bytes: number of bytes

    Returns:
        bytearray
    """
    x_str = hex(data)
    x_str = x_str[2:(2 * num_bytes + 2)]
    i = len(x_str)
    if i < (num_bytes * 2):
        for j in range(0, 2 * num_bytes - i):
            x_str = '0' + x_str
    output = bytes.fromhex(x_str)

    # Change byte order for MCU
    if num_bytes == 2:
        output = bytes([output[1], output[0]])
    return output