in reply to Re: Converting an array of bytes into a BigInt - speed considerations
in thread Converting an array of bytes into a BigInt - speed considerations

Thanks for the suggestions (everyone)!

I just updated Math::BigInt to v1.64 and now my program won't work. Apparently, brsft doesn't return the remainder anymore, only the quotient (it used to return a list with (quo,rem)).

Why, oh, why didn't I pay more attention in math class at college! :)

update: I was just voicing my frustration, not asking anyone to post a solution for me.

-- 
dempa

  • Comment on Re: Re: Converting an array of bytes into a BigInt - speed considerations

Replies are listed 'Best First'.
Re: Re: Re: Converting an array of bytes into a BigInt - speed considerations
by bart (Canon) on Jan 23, 2003 at 16:37 UTC
    That's a bummer. However, it needn't be a total disaster. You can get both quotient and remainder, by making two calls on the same data. For example, band() seems to work just fine as follows, to get at the remainder of a division by 256:
    use Math::BigInt; $a = new Math::BigInt(0xFE78A3); printf '%02X', $a->band(0xFF);
    Result:
    A3
    This is with Math::BigInt version 1.64.

    Update: Yeah, the real solution would be for you to go back to school. ;-)

      Yeah, well I solved it like this:

      sub bigint_to_bytearray { my $bigint = shift; my @bytes; while(1) { push(@bytes,($bigint & 255)); $bigint->brsft(8); last if $bigint == 0; } return @bytes; }

      -- 
      dempa