def ubytes_to_int(bytes_arr, endianness):
    """
     This method is used for turning up to 4 unsigned bytes into signed integers.
    :param list bytes_arr: one to four Bytes which are interpreted as an unsigned Integer
    :param int endianness: determines the order of the bytes: 0 = bigendian, 1 = little endian
    :return: integer
    """
    retval = 0
    length = len(bytes_arr)
    for i in range(0, length):
        if endianness == 0:
            tmpb = bytes_arr[length - i - 1]
        else:
            tmpb = bytes_arr[i]
        if tmpb < 0:
            tmpi = 256 + tmpb
        else:
            tmpi = tmpb
        tmpi <<= i * 8
        retval += tmpi
    return retval
