Questions about Base64 encoding

僤鯓⒐⒋嵵緔 提交于 2021-01-29 08:47:19

问题


I have 3 questions about 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) In past they used 7-bit communication systems, now it's 8-bit. Then why we still using it now?

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:


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.

Isn't text going to be sent through web as binary?

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) see 1)

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%.



来源:https://stackoverflow.com/questions/59294511/questions-about-base64-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!