Reads an unsigned integer with most significant bits first.
$num_bytesintrequired
function read_big_endian( $input, $num_bytes ) {
if ( $num_bytes == 1 ) {
return unpack( 'C', $input ) [1];
} else if ( $num_bytes == 2 ) {
return unpack( 'n', $input ) [1];
} else if ( $num_bytes == 3 ) {
$bytes = unpack( 'C3', $input );
return ( $bytes[1] << 16 ) | ( $bytes[2] << 8 ) | $bytes[3];
} else { // $num_bytes is 4
// This might fail to read unsigned values >= 2^31 on 32-bit systems.
// See https://www.php.net/manual/en/function.unpack.php#106041
return unpack( 'N', $input ) [1];
}
}
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/avifinfo-read_big_endian