0

I have a binary string of the form

"000000110111010100110110001010001010110111010110010001111111101010000001"  # for example

to encode to base 64, i use pack and encode_base64

my $base64 = encode_base64 pack 'B*', $binaryString;

Which I would then get.

A3U2KK3WR/qB

I would like to revert back to the original binary form of the string, I tried

my $binString = decode_base64 $base64;  

but that returns

u6(��G��

How can i revert back the original binary string?

Yusuf Ali
  • 95
  • 2
  • 11

1 Answers1

3

The inverse of

my $base64 = encode_base64(pack('B*', $binary));

is

my $binary = unpack('B*', decode_base64($base64));
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • 3
    Note: I assume length($binary) is always evenly divisible by 8. If its not, there isn't enough information in `$base64` to recreate the original string. – ikegami Sep 30 '14 at 20:00
  • thank you, works perfectly, feeling pretty dump that i forgot to unpack – Yusuf Ali Sep 30 '14 at 20:06