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

  • Thread starter Dmitri Shvetsov
  • 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.
 
C

Chris Hornberger

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top