In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the example analysis on the principle of base64 coding. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Base64 coding principle
Recently, I have been working on converting the file to base64 encoding and saving it in the file. The encoded file is larger than the pre-encoded file by 1 big 3. So I studied the principle of base64 coding.
The Origin of base64 coding
When we transfer files over the network, not all bytes can be transferred. For example, when we send mail, we only support the transmission of visible characters, such as the control characters of ASCII codes cannot be sent through e-mail; not every byte of the binary stream of pictures is visible characters.
At this point, we need to convert invisible characters to visible characters. Hence base64 coding, Base64 is a representation of binary data based on 64 printable characters.
Base64 coding principle
Take a look at the index table of Base64. 64 printable characters are selected: "A murz, a murz, 0-9, +, /". Numeric values represent the index of characters, which is specified in the standard Base64 protocol and cannot be changed. 64 characters can be represented by 6 bit bits, there are 8 bit bits in a byte, and the remaining two bit are wasted, so some space has to be sacrificed. What you need to understand here is that a Base64 character is 8 bit, but the valid part is only the 6 bit on the right, and the two on the left are always 0.
First of all, let's look at an example of how to convert characters to base64 encoding, which is easier to understand.
First of all, we convert the characters into binary, divide the binary data into the valid values of base64 every 6 bits, and then fill 0 before, and convert the 8-bit binary to decimal data after filling 0. The decimal data is the index encoded by base64, and you can find the corresponding code according to the index.
The minimum common multiple of 8 and 6 is 24, which means that 3 traditional bytes can be represented by 4 Base64 characters, ensuring that the number of significant digits is the same, thus adding 1 Base64 3 bytes to make up for the deficiency that Base64 has only 6 valid bit. As a result, the size of the file is also increased by 1 stroke 3.
The principle is that the smallest unit of Base64 characters is a set of four characters, so this is only two characters, followed by two "=". In fact, there is no need for "=" and no delay in decoding. The reason for using "=" may be that the combination of multi-segment encoded Base64 strings will not cause confusion. Thus it can be seen that only one or two "=" can appear at the end of the Base64 string, and it is impossible to have a "=" in the middle.
This is the end of this article on "sample Analysis of base64 coding principles". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.