RedDragon has asked for the wisdom of the Perl Monks concerning the following question:

this subroutine does dectobin convertion and the resulting binary has a maximum of 32 bits.for larger decimal values the convertion fails as the maximum bits is only 32.what do i do for larger decimal values?how can i modify this subr- -outine to do the same?
sub dectobin { join '', unpack "B32", pack "N", shift; }
cheers
yoshi

Replies are listed 'Best First'.
•Re: decimal to binary convertion
by merlyn (Sage) on May 18, 2002 at 08:14 UTC
Re: decimal to binary convertion
by I0 (Priest) on May 19, 2002 at 00:58 UTC
    sub dectobin { use Math::BigInt; my $x = Math::BigInt->new(shift); join '', unpack 'B32B32', pack'NN',$x>>32,$x&0xffffffff; } print dectobin "12297829382473034410";