开发者

Finding if the system is little endian or big endian with perl

开发者 https://www.devze.com 2022-12-26 01:55 出处:网络
Is there an option to find if my system is little endian byte order or big endian byte order开发者_StackOverflow社区 using Perl?perl -MConfig -e \'print \"$Config{byteorder}\\n\";\'

Is there an option to find if my system is little endian byte order or big endian byte order开发者_StackOverflow社区 using Perl?


perl -MConfig -e 'print "$Config{byteorder}\n";'

See Perl documentation.

If the first byte of the output string is 1, you can assume (with moderate safety) that it is little-endian. If it is 4 or 8, you can assume big-endian.


I guess you could do:

$big_endian = pack("L", 1) eq pack("N", 1);

This might fail if your system has a nonstandard (neither big-endian nor little-endian) byte ordering (eg PDP-11).

0

精彩评论

暂无评论...
验证码 换一张
取 消