Introduction
Different systems or protocols can accept different data types. If data transmission is to be performed in those systems or protocols that do not support existing data formats, data conversion is required.
The full name of IANA is The Internet Assigned Numbers Authority, also known as the Internet Assigned Numbers Authority. It is an agency responsible for coordinating Internet affairs and making the Internet work normally. It defines several transfer encodings.
Today, I will give you a detailed explanation of the origin and usage scenarios of these methods.
IANA's transfer encoding
According to the definition of IANA, there are the following transfer encodings:
Name | Reference |
---|---|
7bit | [RFC2045] |
8bit | [RFC2045] |
binary | [RFC2045] |
quoted-printable | [RFC2045] |
base64 | [RFC2045] |
What do these transfer encodings mean? Next one by one.
7bit
We know that the first character encoding of the computer is the ASCII encoding, which represents the range from 0 to 127. A byte is 8 bits, 0 to 127 means that ASCII encoding only uses 7 bits, which is the origin of 7 bits.
For some protocols or systems, they only support ASCII encoding, and if the transmitted data range exceeds 7bit, an exception will occur.
8bit
7bit has great limitations in use, because for commonly used Unicode encoding, 2-4 bytes are usually used as the carrier of information. If it is 7bit, it will lead to incomplete information reception and data loss. original meaning.
8bit means that the entire 8bit data can be received, which means that the data can be transmitted by the entire byte. This way there is no transfer restriction. Therefore, the application of 8bit will be more extensive. If a system can receive 8bit correctly, then we can call this system 8-bit clean.
binary
Is 8bit suitable for all systems? We need to know that 8bit is transmitted in bytes. So it is not suitable for binary streams with a more compact format. So there is a special binary message format binary to deal with binary information.
quoted-printable
What if the data is in binary format, but the system does not support binary format?
At this time, we need to convert binary to text format, which is called Binary-to-text encoding. Among them, quoted-printable and base64 are two conversion methods.
For quoted-printable, it is to represent an 8-bit data with 7-bit readable characters. Although 7bit can represent the range of 0-127, only 33 to 126 are readable characters, and the others are not readable characters.
So how does quoted-printable convert?
In quoted-printable, any 8-bit byte value can be encoded in 3 characters. = followed by two hexadecimal numbers.
For example, for the ASCII form feed character 12, the conversion is =0C. Because = is a special character, the equal sign also needs to be escaped to =3D to represent it.
For printable ASCII characters, that is, decimal values between 33 and 126, no escaping is required, just represent themselves.
ASCII tab and space characters, decimal values 9 and 32 can be represented by themselves unless these characters appear at the end of an encoded line. In this case they need to be escaped as =09 (tab) or =20 (space), or followed by = (soft newline) as the last character of the encoded line.
In addition, a line of Quoted-Printable encoded data must not exceed 76 characters. If that is exceeded, soft line breaks can be added as needed. Soft newlines consist of adding = at the end of the encoded line, soft newlines do not appear as newlines in decoded text.
base64
In addition to quoted-printable, there is also a commonly used Binary-to-text encoding called base64.
The principle of base64 is to map binary codes into 64 characters (26 lowercase letters + 26 uppercase letters + 10 numbers + plus signs and slashes) through a mapping table.
Each Base64 character can represent 6 bits of data, so 3 bytes of data can be represented by 6 Base64 characters.
Its mapping table is as follows:
Summarize
The above are several transfer encoding formats introduced by IANA. Have you learned it?
This article has been included in http://www.flydean.com/13-transfer-encodings/
The most popular interpretation, the most profound dry goods, the most concise tutorials, and many tricks you don't know are waiting for you to discover!
Welcome to pay attention to my official account: "Program those things", understand technology, understand you better!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。