in reply to Binary to Decimal Translation

I'm afraid I cannot replicate your problem. Running Perl 5.6.1 under Windows NT, the following code:
sub dec2bin { my $str = unpack("B32", pack("N", shift)); $str =~ s/^0+(?=\d)//; # otherwise you'll get leading zeros return $str; } sub bin2dec { return unpack("N", pack("B32", substr("0" x 32 . shift, -32))); } print bin2dec("101")," ",bin2dec("111"),"\n"; print dec2bin(5), " ",dec2bin(7) ,"\n";
..produces:
5 7 101 111
..exactly as expected. Perhaps you could show up some of the code that attempts to use these functions? Or perhaps I'm misunderstanding you when you state you "get the exact same binary out."

 
perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re: Re: Binary to Decimal Translation
by cyocum (Curate) on Jul 13, 2001 at 02:15 UTC
    My bad. I was using an object to wrap some of the funtionality. I forgot to my $self = shift;. It was trying to turn the ref into binary and doing a good job too. Just reminds me that garbage in garbage out.