Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Change endianness of a decimal number in PHP
<?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
You can’t perform that action at this time.