Created
September 24, 2014 10:36
-
-
Save PWBENNETT/2656c3b06c825b11e59d to your computer and use it in GitHub Desktop.
BigInt always gives me the wiggins when I try to use it. I don't know whether this is going to explode, or work perfectly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub as_n128 { | |
my $self = shift; | |
my $rv; | |
{ | |
use Math::BigInt try => 'GMP,Pari,Calc'; | |
my $accum = Math::BigInt->new('0'); | |
my $factor = Math::BigInt->new('1')->blsft(Math::BigInt->new('32')); | |
for my $i (map { $_ * 4 } 0 .. 3) { | |
$accum->bmul($factor); | |
$accum->badd(Math::Bigint->new('' . unpack 'N32', substr($self->{ address }, $i, 4))); | |
} | |
$rv = "$accum"; | |
no Math::BigInt; | |
} | |
return $rv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment