计算大小为基带64 codeD消息 [英] Calculate the size to a Base 64 encoded message

查看:132
本文介绍了计算大小为基带64 codeD消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的基地64编码我现在一个二进制字符串,我需要知道手前的最后基地64 EN codeD字符串大小会。

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.

有什么方法来计算?

是这样的:

BinaryStringSize为64KB
恩codedBinaryStringSize将编码后127KB。

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

呵呵,code是在C

Oh, the code is in C.

感谢。

推荐答案

如果你做的Base64 究竟的右,这包括用填充 = 字符结束,你打破它一个 CR LF 每72个字符,答案可以找到:

If you do Base64 exactly right, and that includes padding the end with = characters, and you break it up with a CR LF every 72 characters, the answer can be found with:

code_size    = ((input_size * 4) / 3);
padding_size = (input_size % 3) ? (3 - (input_size % 3)) : 0;
crlfs_size   = 2 + (2 * (code_size + padding_size) / 72);
total_size   = code_size + padding_size + crlfs_size;

在C语言中,你也可以用 \\ 0 - 字节终止,所以会在那里一个额外的字节,你可以在需要的长度检查每code端为你写他们,所以如果你只是找你传递什么的malloc(),你实际上可能preFER版本即浪费的几个字节,以使编码更简单:

In C, you may also terminate with a \0-byte, so there'll be an extra byte there, and you may want to length-check at the end of every code as you write them, so if you're just looking for what you pass to malloc(), you might actually prefer a version that wastes a few bytes, in order to make the coding simpler:

output_size = ((input_size * 4) / 3) + (input_size / 96) + 6;

这篇关于计算大小为基带64 codeD消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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