如何让在字节序Java或Python? [英] how to get endianess in Java or python?
问题描述
在 C
机器我可以在字节序
通过下面的方法。我该如何获得使用蟒蛇
或的Java
程序?在Java中,char是 2字节
与 C
地方是 1字节
。我想可能无法用蟒蛇
,因为它是一个动态语言
,但我可能是错的。
布尔isLittleEndian()
{
psented作为0100英特尔// 16位的值,再$ P $和其他×0001
空头格局= 0×0001;
//获得第一个字节,将1对英特尔和其他0
回*(字符*)及模式== 0×01;
}
在Java中,它只是
ByteOrder.nativeOrder();
...返回要么 BIG_ENDIAN
或 LITTLE_ENDIAN
。
<一个href=\"http://docs.oracle.com/javase/6/docs/api/java/nio/ByteOrder.html\">http://docs.oracle.com/javase/6/docs/api/java/nio/ByteOrder.html
In C
I could the Endianess
of the machine by the following method. how would I get using a python
or Java
program?. In Java, char is 2-bytes
unlike C
where it is 1-byte
. I think it might not be possible with python
since it is a dynamic language
, but I could be wrong
bool isLittleEndian()
{
// 16 bit value, represented as 0x0100 on Intel, and 0x0001 else
short pattern = 0x0001;
// access first byte, will be 1 on Intel, and 0 else
return *(char*) &pattern == 0x01;
}
In Java, it's just
ByteOrder.nativeOrder();
...which returns either BIG_ENDIAN
or LITTLE_ENDIAN
.
http://docs.oracle.com/javase/6/docs/api/java/nio/ByteOrder.html
这篇关于如何让在字节序Java或Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!