Understand encode and decode

2023-01-18

Two terms are super confusing in a subtle way. I have found the following understandings are helpful.

We need to understand “code” first. Code means a thing that is good at transport or storage and requires computation to unpack the original values that serves as an input to human or a program. Encode means turning into “code”, while decode means turning "code" into something that serves as a input. For example, for ASCII string is the thing for human to read. To encode ASCII string, we turn it into bytes (a sequence of 8 bits integers) which is suitable for storage into a disk on a machine or send across the Network.

Another example is bech32. The code of bech32 is a ASCII string, which is easy to type by human, and the decode of bech32 is tuple of string, and a bytes which is meaningful to programs as input. The code of bech32 can also be an QR code image which can be easy for transport using the camera on a modern phone.

Notice in two examples, the "code" of something can be string, bytes or even an image dependings on the what one we decide to be the transport. The decode is what we decide to be the thing that human or a program takes as the input.