Base64编码:什么是空间使用最坏的可能增加? [英] Base64: What is the worst possible increase in space usage?

查看:115
本文介绍了Base64编码:什么是空间使用最坏的可能增加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个服务器收到一个base64字符串,并要检查它的长度在转换之前,,说,它希望总是允许最终字节数组是16KB。有多大可能当转换到Base64字符串16KB字节数组可能成为(假设每个字符一个字节)?

If a server received a base64 string and wanted to check it's length before converting,, say it wanted to always permit the final byte array to be 16KB. How big could a 16KB byte array possibly become when converted to a Base64 string (assuming one byte per character)?

推荐答案

Base64的EN codeS每组三个字节为四个字节。此外,输出被填充到始终是4的倍数。

Base64 encodes each set of three bytes into four bytes. In addition the output is padded to always be a multiple of four.

这意味着,大小为n的串的基64重新presentation的大小是:

This means that the size of the base-64 representation of a string of size n is:

ceil(n / 3) * 4

因此​​,对于16KB阵列,基部64重新presentation将CEIL(16 * 1024/3)* 4 = 21848个字节长。

So, for a 16KB array, the base-64 representation will be ceil(16*1024/3)*4 = 21848 bytes long.

这篇关于Base64编码:什么是空间使用最坏的可能增加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆