Base64 string from byte array - what's the length ratio ?

  • Thread starter Thread starter Dmitri Shvetsov
  • Start date Start date
D

Dmitri Shvetsov

Hi All,

Does somebody know what's the length's ratio in we convert byte[] to base64
string? Is it a constant ratio or it can be different from case to case? For
example if I convert a byte array of 20 bytes length can I expect that I get
the base64 string with the same length every time when I do that? And what
will be the maximum length of this string?

What's the schema is taken for this conversion? If we use UUENCODE or
something else we can predict the string length converting a byte array. Can
we do the same in this case?

Regards,
Dmitri.
 
Base64 encoding turns 3 bytes into 4 in the conversion.

Specifically, it encodes 6 bits into 8 bits, so looking at proper
boundaries, it takes 3 bytes to properly fence-post 6bit chunks. The
encoding then expands them to 8 bits to allow ascii representation of
non-ascii data (binary data) where applicable.
 
Back
Top