Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Change endianness of a decimal number in PHP
* Change endianness of the given decimal number.
* @param int $num
* @return int
function num_endianness($num) {
$hex = dechex($num);
if (strlen($hex) <= 2) {
return $num;
return hexdec(unpack('H*', strrev(pack('H*', $hex)))[1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment