0

So I'm studying for the upcoming exam, and there's this question: given a binary file with the size of 31 bytes what will its size be, after encoding it to base64?

The solution teacher gave us was (40 + 4) bytes as it needs to be a multiple of 4.

I'm not being able to come across this solution, and I have no idea how to solve this, so I was hoping somebody could help me figure this out.

jruivo
  • 447
  • 1
  • 8
  • 22
  • http://stackoverflow.com/questions/4715415/base64-what-is-the-worst-possible-increase-in-space-usage – Marged Jan 02 '16 at 22:17

1 Answers1

2

Because base 64 encoding divide the input data in six bit block and one block use an ascii code. If you have 31 byte in input you have 31*8/6 bit block to encode. As a rule of thumb every three byte in input you have 4 byte in output If input data is not a multiple of six bit the base64 encoding fills the last block with 0 bit In your example you have 42 block of six bit, with last filled with missing 0 bit. Base 64 algorithm implementation filled the encoded data with '=' symbol in order to have of multiple of 4 as final result.

alangab
  • 849
  • 5
  • 20