Created
December 3, 2017 00:39
-
-
Save rouben/ecf7f7300eb1d9c00b28ea33b9ac77b5 to your computer and use it in GitHub Desktop.
Endianness check in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Taken from https://stackoverflow.com/questions/9744904/how-to-get-the-endianness-type-in-php | |
*/ | |
function isLittleEndian() { | |
$testint = 0x00FF; | |
$p = pack('S', $testint); | |
return $testint===current(unpack('v', $p)); | |
} | |
if (isLittleEndian()) { | |
echo "Little endian.\n"; | |
} | |
else | |
{ | |
echo "Big endian.\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment