Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of base64 coding

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

What is the principle of base64 coding? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

The principle of base64 coding is to split an 8-bit sub-section sequence into 6-bit segments and assign a character to each 6-bit segment. The 64 characters are lowercase letters [Amurz], uppercase letters [AMEZ], numbers [0-9], symbols [+], [/].

The principle of base64 coding is as follows:

Base64 code splits a sequence of 8-bit subsections into 6-bit segments and assigns one character to each 6-bit segment. The 64 characters-lowercase letters Amaz, uppercase AMEZ, numbers 0-9, symbols "+", "/", see here, you know what 64 means. It represents 64 characters. In fact, there is a "=" of a pad word, which is actually 65 characters.

The Base64 rules are as follows:

The first step is to set every three bytes as a group, with a total of 24 bits.

The second step is to divide the 24 binary bits into four groups, each with 6 binary bits.

The third step is to add two 00s in front of each group to expand into 32 binary bits, that is, four bytes. So the base64 encoded string is about 33% larger than the original.

Examples

Give a concrete example to demonstrate how the English word Man is converted into Base64 coding.

In the first step, the ASCII values of "M", "a" and "n" are 77, 97, 110, respectively, and the corresponding binary values are 01001101, 01100001, 01101110, concatenating them into a 24-bit binary string 01001101010000101101110.

The second step is to divide the 24-bit binary string into four groups, each with six binary bits: 010011, 010110, 000101, 101110.

The third step is to add two 00s in front of each group to expand into 32 binary bits, that is, four bytes: 00010011, 00010110, 00000101, 00101110. Their decimal values are 19, 22, 5, 46, respectively.

The fourth step, according to the following figure, get each value corresponding to the Base64 code, that is, T, W, F, u.

Therefore, the Base64 code of Man is TWFu.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report