What's does “machine byte order” in PHP pack mean? [closed]

耗尽温柔 提交于 2020-01-30 10:54:07

问题


I understand little & big endian, but What's "machine byte order" mean?


回答1:


In pack the phrase "machine byte order" means that the endianess is determined by the current machine1

PHP itself makes no guarantees as to which endianness such characters (e.g. S, L) encode data, except as the ordering relates to the current machine.

Therefor, be cautious with using "machine byte order" pack characters and consider the guaranteed-order counter-parts (e.g. n, v) if there is every any doubt1. However, pay attention to the target data specification as some silly formats like [Microsoft] UUIDs are laid out in terms of "machine byte order" while others are always big-endian or always little-endian.


1 x86/x64 is always little-endian, but PHP could technically run on big-endian machines .. somewhere. It is best to get into the habit of being explicit and precise to avoid having code suddenly and mysteriously "stop working" later on.



来源:https://stackoverflow.com/questions/12430718/whats-does-machine-byte-order-in-php-pack-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!