how to get endianess in Java or python?

后端 未结 4 1123
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-14 05:08

In C I could the Endianess of the machine by the following method. how would I get using a python or Java program?. In Ja

4条回答
  •  礼貌的吻别
    2021-01-14 05:46

    You can use sys.byteorder:

    >>> import sys
    >>> print sys.byteorder
    'little'
    

    Or you can get endianness by yourself with a little help of the built-in struct module:

    import struct
    
    def is_little():
        packed = struct.pack("i", 1)
        return packed[0] == "\x01";
    
    print is_little()
    

    That was all Python of course.

提交回复
热议问题