问题描述
我有3个关于base64的问题:
I have 3 questions about base64:
1)base64编码的目的是二进制到文本.文本不是要以二进制形式通过网络发送吗?那有什么好处呢?
1) The base64 encoding purpose is binary-to-text. Isn't text going to be sent through web as binary? Then what is good for?
2)过去他们使用7位通信系统,现在是8位.那为什么我们现在仍在使用它呢?
2) In past they used 7-bit communication systems, now it's 8-bit. Then why we still using it now?
3)如何增加尺寸?我只用28位元的3个位元组,然后将它们重新排列为4位元组的6位元,但总的还是28位元?
3) How it increases the size? I just take 3-bytes with 28-bit and rearrange them to 4-bytes of 6-bit but in total they still 28-bit?
推荐答案
1)目的不仅是二进制到文本编码,还用于编码使用超出标准7位ASCII码的特定字符集/代码页的文本.对于二进制数据,您还会遇到某些值导致问题的问题.当通过电子邮件或HTTP请求的一部分进行传输时,数据中的值0可以解释为文本的结尾.在接收方,前0之后的所有内容都可能被遗忘",并且数据将被破坏.Base64编码通过将所有字符编码为64个字符的子集来避免所有可能的问题,这些字符与实际代码页无关,并且不包含任何控制字符.
1) The purpose is not only binary to text encoding, but also to encode text which uses specific character sets/codepages that go beyond the standard 7 bit ASCII code. In case of binary data you also have the problem that certain values cause problems. A value of 0 in your data could be interpreted as the end of the text, when transmitted in an email or a part of a HTTP Request. On the receiving side, everything after the first 0 might be 'forgotten' and the data would be corrupted. Base64 encoding avoids all the possible problems by encoding everything in a subset of 64 characters which are independent from the actual codepage and don't contain any control characters.
在幕后,一切都是二进制的,无论是文本,图片,电影还是执行的代码,在存储器和处理器寄存器中都是一堆零和一.
Under the hood everything is binary, be it a text, a picture, a movie, the code that is executed, it's all just a bunch of zeroes and ones in the memory and processor registers.
2)参见1)
3)3个字节是3 * 8位= 24位信息.基本64个字符仅代表6位,因此您需要4个基本64个字符4 * 6位= 24位以对信息进行编码.但是这些base64字符是正常的8位字符,因此实际上这4个base64字符占据4 * 8位= 32位的空间.增长了33%.
3) 3 bytes are 3 * 8 bits = 24 bits of information. A base 64 character just represents 6 bits, therefore you need 4 base64 characters 4 * 6 bits = 24 bits to encode the information. But these base64 characters are normal 8 bit characters, so in fact these 4 base64 characters occupy a space of 4 * 8 bits = 32 bits. That's an increse of 33%.
这篇关于有关Base64编码的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!