character encoding

The rule for turning text characters into bytes and back, such as UTF-8.

In more detail

Text is stored and sent as bytes, and an encoding such as UTF-8 says which bytes mean which characters. Decoding with the wrong encoding produces garbled text or an error, so formats and protocols declare the encoding they use. Naming the encoding explicitly, usually UTF-8, avoids depending on an operating system default.

Examples

msg.value.decode()
In the browser: a network response is only bytes until it is decoded, and declaring the encoding early with a meta charset tag or a response header avoids guessing and re-parsing.
Node.js Buffers support encodings such as "utf8", "hex", "base64" and "latin1" in Buffer.from() and buf.toString().
open("cafe.txt", "w", encoding="utf-8")

Related terms

Taught in

References

Certification courses