Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the principle of base64 coding

Shulou Source: shulou.com Published: 2022-06-03 03:09:30 10月21日 Update

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.

Tags: Binaries characters codes letters fragments principles strings bytes two seats uppercase uppercase lowercase sequences numbers symbols evolution allocation help clarity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno MySQL macOS Shulou Tech Info