-1

I have string of 2 bits (1s and 0s) that is 64 bits/chars long and I would like to base64_encode it in PHP. How do I convert it to base64?

Here is my string (the right-most char is the 1st bit and the left-most char is the 64th bit):

$strBinData = '0110011111011010110101100100000000000000000100000000000010010011' ;

By the way I am using PHP v5.3.24.

user1822391
  • 399
  • 3
  • 13

1 Answers1

1

I'm not entirely sure what you want to do but you can convert your binary string to an int value and then use base64_encode:

$decimalValue = intval($strBinData, 2);
$base64 = base64_encode($decimalValue);

Let me know if this isn't what you wanted to do.

jxmallett
  • 4,087
  • 1
  • 28
  • 35