In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the principle of Base64 coding". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the principle of Base64 coding".
Base64 is a representation of binary data based on 64 printable characters. Since the sixth power of 2 is 64, every six bits is a unit, corresponding to a printable character. 3 bytes have 24 bits, corresponding to 4 Base64 units, that is, 3 bytes can be represented by 4 printable characters. It can be used as the transmission code of e-mail. The printable characters in Base64 include the letters Amurz, Amurz, and the numbers 0-9, so there are 62 characters in total. In addition, the two printable symbols vary in different systems. In MIME format, the remaining two characters are the plus sign + and the slash /, and the equal sign = is used as a suffix. UTF-7 is a modified version of Base64, the main difference is that there is no need for the equal sign = complement, because the character usually requires a lot of translation. In the P10 IRC inter-server protocol used by software such as IRCu, the + / is changed to []. Base64 encoding can be used to pass in the HTTP environment without the = sign at the end, and the + and / in the standard Base64 are changed to-and _, respectively.
The principle of base64
The data encoded by base64 is slightly longer than the original data, which is longer than the original data. Why does it grow 1Accord 3? Let's learn the principle, and then base64 will never get in the way in our work. During the conversion, 3 bytes of data are put into a 24-bit buffer successively, and the first-come bytes occupy the high bit. If the data is less than 3 bytes, make up the remaining bits in the buffer with 0. 6 bits are taken out each time, and the characters in ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ are selected as the encoded output according to their values until all input data conversion is completed. If the original data length is not a multiple of 3 and one input data is left, two = is added after the coding result; if there are two input data left, one = is added after the coding result. In other words, the original 3 bytes, base64 through its own encoding to 4 bytes. It's 1 beat 3 more than the principle. Come on, for example.
Text hel
Ascii code 104101108
Binary 011010000110010101101100
Base64 6-bit 01101000 0110010101101100base64 decimal numbered 2662144base64 result aGVs
The result of base64 coding of hel is aGVs.
Base64 code table
Application of base64
Base64 has a wide range of applications, and individuals encounter the most two aspects in development, the first is URL's base64, and the other is picture base64. First of all, there is already urlencode, so why do you still need base64's URL? Each has its own purpose. Urlencode is going to-_. All non-alphanumeric characters outside are replaced with a percent sign (%) followed by two hexadecimal digits, and spaces are encoded with a plus sign (+). If there are + spaces in a URL, it can not be solved by urlencode, and it can be easily solved by using base64. The cost is that URL is one more than the principle.
The problem of image coding is often with the client development, when the client uses the binary stream to upload the picture is more complex, you can use base64 to convert the binary coding of the picture into base64, and the server receives the data and then basedecode the binary stream of the picture. It is very convenient, and as a result, more data is transmitted.
Problems encountered
According to RFC 822, you need to add a carriage return for every 76 characters. In some languages, when a newline character is found in base64decode, decode fails. The reason is that there are many line breaks and decoding failure in decode. If you know the reason, it is very simple to replace the newline character\ r |\ r\ nwith empty, and then base64decode.
Thank you for your reading, these are the contents of "what is the principle of Base64 coding?" after the study of this article, I believe you have a deeper understanding of what the principle of Base64 coding is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.