Alex Rivera | Logout

Calculate the size to a Base 64 encoded message

Asked 2009-10-07T17:39:48.910
30

I have a binary string that I am encoding in Base 64. Now, I need to know before hand the size of the final Base 64 encoded string will be.

Is there any way to calculate that?

Something like:

BinaryStringSize is 64Kb EncodedBinaryStringSize will be 127Kb after encoding.

Oh, the code is in C.

Thanks.

Edit
Report

2 Answers

2

Base 64 transforms 3 bytes into 4.

If you're set of bits does not happen to be a multiple of 24 bits, you must pad it out so that it has a multiple of 24 bits (3 bytes).

answered 2009-10-07T17:48:21.107
2

I think this formula should work:

b64len = (size * 8 + 5) / 6
answered 2012-07-24T17:19:38.933

Your Answer