问题
#!/usr/bin/env perl
use warnings;
use 5.012;
my $var = 1 << 31;
say unpack( "B*", pack( "N", $var ) );
# 10000000000000000000000000000000
How can I get with pack/unpack from
my $var = 1 << 63;
an output like this?
# 1000000000000000000000000000000000000000000000000000000000000000
回答1:
say unpack("B*", pack( "Q>", $var ));
The >
forces big-endian byte-order on the Q
(unsigned 64-bit "quad") type.
来源:https://stackoverflow.com/questions/4672213/pack-unpack-litle-endian-64bit-question