Java 虚拟机的字节序

标签 java virtual-machine endianness

Java 在其虚拟机中使用什么字节序?我记得在某处读到它取决于它运行的物理机器,然后在我读过的其他地方我相信它总是大端。哪个是正确的?

最佳答案

class 中的多字节数据文件以大端方式存储。

来自 The Java Virtual Machine Specification, Java SE 7 Edition , Chapter 4: The class File Format :

A class file consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit quantities are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multibyte data items are always stored in big-endian order, where the high bytes come first.

此外,如果字节码指令中的操作数跨越多个字节,它也是大端的。

来自 The Java Virtual Machine Specification, Java SE 7 Edition , Section 2.11: Instruction Set Summary :

If an operand is more than one byte in size, then it is stored in big-endian order-high-order byte first. For example, an unsigned 16-bit index into the local variables is stored as two unsigned bytes, byte1 and byte2, such that its value is (byte1 << 8) | byte2.

所以是的,我认为可以说Java虚拟机使用大端序。

关于Java 虚拟机的字节序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/981549/

相关文章:

Java 未经检查的操作转换为泛型

java - 当客户端断电或在netty中失去互联网连接时,如何检测客户端在服务器上的断开连接

azure - 如何在 Azure VM 上禁用加速网络

java - java中如何将字节转换为长整型

java - 有 2 个项目的 Eclipse WAR?

java - 简单的java数学函数不起作用

css - 如何在 VM 上运行的 IE8 中添加/编辑 CSS 属性?

spring - 在 Windows 上使用 docker 开发 Spring Boot 应用程序,但在 Ubuntu VM 上运行 docker 容器(作为 Docker 主机)

c++ - 如何在 C++ 中的大端和小端值之间进行转换?

io - 我应该如何阅读有关字节序的文件内容?