in reply to Re: decimal to binary conversion need help
in thread decimal to binary conversion need help

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.

Replies are listed 'Best First'.
Re^3: decimal to binary conversion need help
by zentara (Cardinal) on Jan 06, 2005 at 12:36 UTC
    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
        Thank you for all this help, but i have another problem i am running the code on perl 5.6 and it seems that it is not working please help