字符编码

字符编码相关,ASCII 和 utf-8

ASCII

https://www.ascii-code.com/ISO-8859-1

ASCII control characters (character code 0-31)

The first 32 characters in the ASCII-table are unprintable control codes and are used to control peripherals such as printers.

ASCII printable characters (character code 32-127)

Codes 32-127 are common for all the different variations of the ASCII table, they are called printable characters, represent letters, digits, punctuation marks, and a few miscellaneous symbols. You will find almost every character on your keyboard. Character 127 represents the command DEL.

The extended ASCII codes (character code 128-255)

...

utf-8

UTF-8 最大的一个特点,就是它是一种变长的编码方式。它可以使用1~4个字节表示一个符号,根据不同的符号而变化字节长度。

UTF-8 的编码规则很简单,只有二条:

  1. 对于单字节的符号,字节的第一位设为0,后面7位为这个符号的 Unicode 码。因此对于英语字母,UTF-8 编码和 ASCII 码是相同的。

  2. 对于n字节的符号(n > 1),第一个字节的前n位都设为1,第n + 1位设为0,后面字节的前两位一律设为10。剩下的没有提及的二进制位,全部为这个符号的 Unicode 码。

Unicode符号范围(十六进制)UTF-8编码方式(二进制)字节数
000 0000-0000 007F0xxxxxxx1
0000 0080-0000 07FF110xxxxx 10xxxxxx2
0000 0800-0000 FFFF1110xxxx 10xxxxxx 10xxxxxx3
0001 0000-0010 FFFF11110xxx 10xxxxxx 10xxxxxx 10xxxxxx4