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

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "what is the principle of base64". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Why is there Base64 coding? Because some network transmission channels do not support all bytes, for example, traditional mail only supports the transmission of visible characters, such as ASCII control characters can not be sent through mail. The use of this is greatly limited, for example, every byte of a binary stream of a picture cannot be all visible characters, so it cannot be transmitted. The best way is to make an extension scheme to support the transfer of binary files without changing the traditional protocol. Non-printable characters can also be represented as printable characters, and the problem is solved. Base64 coding arises at the historic moment. Base64 is a representation of binary data based on 64 printable characters.

Index table of Base64

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.

The principle of Base64

The code table of Base64 is only 64 characters. If you want to express 64 characters, you can use the bit of 6 to fully represent it (2 to the power of 6 is 64).

Because Base64 can only be represented by 6 bit, while normal characters are represented by 8 bit, the least common multiple of 8 and 6 is 24, so 4 Base64 characters can represent 3 standard ascll characters.

If the string is converted to Base64 code, the corresponding string will be converted to the corresponding number in the ascll code table, and then the number will be converted to binary. For example, the binary of a's ascll code flavor 97Power97 is: 01100001. Extract the 8 binaries into 6, and the remaining 2 binaries and the following binaries will continue to be stitched together. Finally, the 6 binaries will be converted into Base64 codes. The following is an example of the parsing process:

The process of converting these three characters of abc into Base64

Run the following code

Copy the code

String abc

ASCII979899

8bit011000010110001001100011

6bit011000010110001001100011

Decimal 2422935

Corresponding coding YWJj

Copy the code

The process of converting these three characters of man into Base64

This is the end of the content of "what is the principle of base64". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Development

Wechat

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

12
Report