Perl包使用-双大端?
根据这个计算器站点(),当将3从十进制转换为双精度时,我应该得到Perl包使用-双大端?,perl,binary,endianness,Perl,Binary,Endianness,根据这个计算器站点(),当将3从十进制转换为双精度时,我应该得到4008 0000 在使用Perl函数时,使用参数“d>*”,我希望在使用此函数时看到4008 0000: print $File pack("d>*", 3); 但是当我“hextump”到Perl输出文件时,我看到0840 0000 我以为它可能属于大/小endian,但在尝试小endian时 print $File pack("d<*", 3); print$File pack(“d您对Perl中字节顺序的直觉
4008 0000
在使用Perl函数时,使用参数“d>*”,我希望在使用此函数时看到4008 0000
:
print $File pack("d>*", 3);
但是当我“hextump”到Perl输出文件时,我看到0840 0000
我以为它可能属于大/小endian,但在尝试小endian时
print $File pack("d<*", 3);
print$File pack(“d您对Perl中字节顺序的直觉是正确的,但我认为hexdump输出并不意味着您所认为的那样。它看起来像是hexdump以一致但违反直觉的顺序显示每对字节。下面是一些您可以运行的实验,以了解方向
# bytes are stored in the order that they are printed
$ perl -e 'print "\x{01}\x{02}\x{03}\x{04}"' | od -c
0000000 001 002 003 004
0000004
# perl reads the bytes in the correct order
$ perl -e 'print "\x{01}\x{02}\x{03}\x{04}"' | perl -ne 'print map{ord,$"}split//'
1 2 3 4
# but the way hexdump displays the bytes is confusing (od -h gives same output)
$ perl -e 'print "\x{01}\x{02}\x{03}\x{04}"' | hexdump
0000000 0201 0403
0000004
通过管道进入hex
会产生01 02 03 04
。这是util linux或xxd
中的hextump
版本,并且通常优于该版本。好的,Perl做得很好。解决方案是将“-C”添加到hextump中:“hextump-C[FileName]”将显示预期的结果。