use strict;
use warnings;
use Math::BigInt;
#需求:将一个10进制的大数,用16进制分解成4份
#法1:类似C的写法
my $l = 281474983985353;
my $a = $l % 0x100000000;
my $b = ($l-$a)/0x100000000;
my $major = $b >> 16;
my $minor = $b % 0x10000;
my $build = $a >> 16;
my $ext = $a % 0x10000;
print "$major $minor $build $ext\n";
#法2:用Math::BigInt大数库
my $t = new Math::BigInt('281474983985353');
my @result;
while($t){
my ($t, $s) =$t->bdiv(0x10000);
unshift @result, s;
}
print join(" ", @result, "\n");
#法3:可以用pack,需要支持Q选项,与perl编译的版本有关
没有评论:
发表评论