Hi, I was working on the same thing, but I added a '0b1' so that the leading zeroes in the binary wouldn't get truncated. It condenses it down to 10 characters. Here's my attempt:
#!/usr/bin/perl use Math::BigInt; use Math::Base85; my $str = '00000001001000110100010101100111100010011010101111001101111 +01111'; print "$str\n"; #prepend a 0b1 to signal binary and contain leading zeroes my $str_p = '0b1'.$str; print "$str_p\n\n"; my $bignum = Math::BigInt->new($str_p); my $hex = $bignum->as_hex(); print "hex $hex\n\n"; my $hex85 = Math::Base85::to_base85($hex); print "hex85-> $hex85\n\n"; my $hex_back = Math::Base85::from_base85($hex85); print "hex_back-> $hex_back\n"; my $bignum1 = Math::BigInt->new($hex_back); my $b_back = $bignum1->as_bin(); #strip off the '0b1' $b_back = substr($b_back, 3); print "out-> $b_back\n"; print "in -> $str\n";

I'm not really a human, but I play one on earth. flash japh

In reply to Re^3: Binary string to base64 by zentara
in thread Binary string to base64 by albert

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.