in reply to Binary to Decimal Translation
..produces: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";
..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."5 7 101 111
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 |