更改 PHP 中的字节顺序
因此,我正在 PHP 中创建一个类来解析 VPK 文件格式。
然而我遇到了一个问题:
object(VPKHeader)#2 (3) {
["Signature"]=>
string(8) "3412aa55"
["Version"]=>
string(4) "1000"
["DirectoryLength"]=>
int(832512)
}
签名应该是0x55aa1234,但是我正在读取的签名是0x3412aa55。
如何切换 PHP 中的字节序?
So i'm making a class in PHP to parse the VPK file format.
However i've hit a problem:
object(VPKHeader)#2 (3) {
["Signature"]=>
string(8) "3412aa55"
["Version"]=>
string(4) "1000"
["DirectoryLength"]=>
int(832512)
}
The signature is supposed to be 0x55aa1234, however the signature I'm reading is 0x3412aa55.
How do I switch the endianness in PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的十六进制值始终是字符串,您可以使用以下函数:
同意,它不是最有效的,但在我看来代码非常优雅。此外,它适用于所有大小的数字。
If your hex values will always be strings, you can use the following function :
Agreed, it's not the most efficient, but the code is quite elegant in my opinion. Also, it works with all sizes of numbers.
您必须手动转换该值。该算法将与 C++ 中的算法相同,因此只需移植此代码(您只需要适用于
int
afaik 的代码):来源:http://www.codeguru.com/forum/showthread.php?t=292902
You have to convert the value manually. The algorithm will be the same as it is in C++, so just port this code (you only need the one that works on
int
afaik):Source: http://www.codeguru.com/forum/showthread.php?t=292902