in reply to Binary string to base64
This almost works. I can only get the last half of the bin string back, but maybe the gurus can see the packing error. Maybe needs 64 bit numbers or Math::BigINT?#results 0000000100100011010001010110011110001001101010111100110111101111 -> + iL1@;
#!/usr/bin/perl use strict; use Math::Base85; my $str = "00000001001000110100010101100111100010011010101111001101111 +01111"; #binary to decimal conversion my $num = unpack("N", pack("B32", substr("0" x 32 . $str, -32))); print "$num\n"; my $m = Math::Base85::to_base85($num); print "$str ->\t$m\n"; #decode it ############################################## my $q = Math::Base85::from_base85($m); print "back to decimal ->\t$q\n"; #I'm losing a 32 bit chunk here my $str1 = unpack("B32", pack("N", $q)); print "back to bin ->\n", $str1,"\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Binary string to base64
by albert (Monk) on Jun 16, 2006 at 18:28 UTC | |
by zentara (Cardinal) on Jun 16, 2006 at 21:21 UTC |