ASCII code

Introduction to the

The ASCII Code (American Standard Code for Information Interchange) is a set of computer coding system based on The Latin alphabet. It is the most common single-byte coding system today.

ASCII code can be used to represent upper and lower case English letters and some characters and control characters, but Chinese, Russian and French characters can not be represented, so the subsequent utF-8 can represent global characters to solve this problem.

Corresponding relations between

We know that in Java, a char can be considered an int, for example:

A-Z, a-z, 0-9

The decimal system Corresponding character The decimal system Corresponding character The decimal system Corresponding character
65 A 97 a 48 0
66 B 98 b 49 1
67 C 99 c 50 2
68 D 100 d 51 3
69 E 101 e 52 4
70 F 102 f 53 5
71 G 103 g 54 6
72 H 104 h 55 7
73 I 105 i 56 8
74 J 106 j 57 9
75 K 107 k
76 L 108 l
77 M 109 m
78 N 110 n
79 O 111 o
80 P 112 p
81 Q 113 q
82 R 114 r
83 S 115 s
84 T 116 t
85 U 117 u
86 V 118 v
87 W 119 w
88 X 120 x
89 Y 121 y
90 Z 122 z

Base64 encoding

meaning

There are many existing character sets, such as UTF-8 / GBK, which are not supported in some transmission channels. For example, mail transmission does not support the control characters in the ASCII code above. Base64 is created to solve this problem.

Corresponding relations between

64 in Base64 refers to 64 characters, a-z, A-z, 0-9, +, / they correspond to the decimal system as follows:

The numerical character The numerical character The numerical character
0 A 26 a 52 0
1 B 27 b 53 1
2 C 28 c 54 2
3 D 29 d 55 3
4 E 30 e 56 4
5 F 31 f 57 5
6 G 32 g 58 6
7 H 33 h 59 7
8 I 34 i 60 8
9 J 35 j 61 9
10 K 36 k
11 L 37 l 62 +
12 M 38 m 63 /
13 N 39 n
14 O 40 o
15 P 41 p
16 Q 42 q
17 R 43 r
18 S 44 s
19 T 45 t
20 U 46 u
21 V 47 v
22 W 48 w
23 X 49 x
24 Y 50 y
25 Z 51 z

How to Base64 codec ASCII code

Base64 has 64 characters, 2^6 = 64, so each Base64 encoded character can be represented by a 6-bit binary. So if you have a 3-byte binary, you can use 4-bit Base64 characters.

The coding process is as follows:

  1. ASCII character strings are converted to binary values according to the ASCII comparison table.
  2. Divide binary values into six bits;
  3. Then the 6-bit binary is converted to decimal to find Base64 encoded characters according to the comparison table.

For example,

What if the length of the encoded string is not a multiple of three? In this case, the ASCII converted binary string cannot be divisible by 6 and therefore cannot be encoded as Base64. In this case, in order to compile the full number of bytes divisible by 6, you need to fill in with 0 bits. If there are six zeros in a row, it is denoted by =.

For example,

I believe that after looking at these two examples, we have a clear understanding of the Base64 encoding process.