Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何判断ctypes整数类型是否为big-endian?_Python_Ctypes - Fatal编程技术网

Python 如何判断ctypes整数类型是否为big-endian?

Python 如何判断ctypes整数类型是否为big-endian?,python,ctypes,Python,Ctypes,考虑以下几点: le = ctypes.c_uint32.__ctype_le__ be = ctypes.c_uint16.__ctype_be__ 我如何编写一个函数is_bigendiancls,它的行为与您期望的一样: >>> is_bigendian(le) False >>> is_bigendian(be) True ctypes是否在某处公开了此信息?似乎唯一可能的方法是: if ctypes.c_uint8.__ctype_be__.__

考虑以下几点:

le = ctypes.c_uint32.__ctype_le__
be = ctypes.c_uint16.__ctype_be__
我如何编写一个函数is_bigendiancls,它的行为与您期望的一样:

>>> is_bigendian(le)
False
>>> is_bigendian(be)
True

ctypes是否在某处公开了此信息?

似乎唯一可能的方法是:

if ctypes.c_uint8.__ctype_be__.__name__.endswith('_be'):
    def is_bigendian(cls):
        return cls.__name__.endswith('_be')
elif ctypes.c_uint8.__ctype_le__.__name__.endswith('_le'):
    def is_bigendian(cls):
        return not cls.__name__.endswith('_le')
else:
    raise RuntimeError
这很难识别,因为reprctypes.c_uint8.\uuuu ctype_be\uuuuuuuuu无法正确显示类名。

无法区分它们,因此您可能会被忽略。