in reply to decimal to binary conversion need help

Update: Corrected. Number needs to be as "string".

#!/usr/bin/perl use Math::BigInt; my $bignum = Math::BigInt->new('9007199254740991'); print $bignum->as_bin(),"\n";

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: decimal to binary conversion need help
by holli (Abbot) on Jan 06, 2005 at 12:23 UTC
    or even:
    use bigint; my $bignum = 9007199254740991; print $bignum->as_bin(),"\n";
    but then all numbers are BigInts, that might lead to a slower script.
      I don't know what the restrictions are with "use bigint", but it dosn't give the same result.???? Differ by 1.
      #!/usr/bin/perl use Math::BigInt; my $bignum = Math::BigInt->new(9007199254740991); print $bignum->as_bin(),"\n"; ######################################################## use bigint; my $bignum = 9007199254740991; print $bignum->as_bin(),"\n"; __END__
      Results:

      0b11111111111111111111111111111111111111111111111111110 0b11111111111111111111111111111111111111111111111111111

      I'm not really a human, but I play one on earth. flash japh
        Oops, I guess BigInt wants a string, not a number.
        my $bignum = Math::BigInt->new('9007199254740991'); print $bignum->as_bin(),"\n"; ######################################################## use bigint; my $bignum = 9007199254740991; print $bignum->as_bin(),"\n";
        #Correct results:
        0b11111111111111111111111111111111111111111111111111111 0b11111111111111111111111111111111111111111111111111111

        I'm not really a human, but I play one on earth. flash japh