如何让在字节序Java或Python? [英] how to get endianess in Java or python?

查看:205
本文介绍了如何让在字节序Java或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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆