我正在尝试编写一个 ROM 文件修补程序,我在文档中找到了这一点:
The next three bytes are the place in the destination file
(the file to be patched) where a change is to be made.
The two bytes following that are the length of the amount
of data to be changed.
如何在 java 中正确地将这三个和两个字节转换为单个数字?
最佳答案
奇怪的是,我看到 Joey 的有效答案,他在 10 分钟前删除了该答案:
(byte1 << 16) + (byte2 << 8) + byte3
我唯一要补充的是:不要将从 InputStream 读取的字节转换为 byte
类型(InputStream#read
返回 int
值0 到 255 之间)。例如,这会将 255
转换为 -1
,而我们不需要这样的副作用。
所以,它可能看起来像
(in.read() << 16) + (in.read() << 8) + in.read()
关于java - 如何将多个字节加在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4001614/