gpt4 book ai didi

Java 虚拟机的字节序

转载 作者:IT老高 更新时间:2023-10-28 21:05:51 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com