how to get endianess in Java or python?

后端 未结 4 1146
佛祖请我去吃肉
佛祖请我去吃肉 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:28

    The (byte) cast of short is defined in both Java and C to return the "little" end of the short, regardless of the endianness of the processor. And >> is defined to shift from "big" end to "little" end (and << the opposite), regardless of the endianness of the processor. Likewise +, -, *, /, et al, are all defined to be independent of processor endianness.

    So no sequence of operations in Java or C will detect endianness. What is required is some sort of "alias" of one size value on top of another (such as taking the address of an int and casting to char*), but Java does not have any way to do this.

提交回复
热议问题