Skip to content

Instantly share code, notes, and snippets.

@PWBENNETT
Created September 24, 2014 10:36
Show Gist options
  • Save PWBENNETT/2656c3b06c825b11e59d to your computer and use it in GitHub Desktop.
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.
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