itslabtime.com

Information · Computing · Data Representation

Binary numbers and character encoding

A bit sequence’s meaning depends on how it is interpreted. The same 0s and 1s can represent integers, characters, or colors.

Related experiment: Binary numbers and character encoding →
Binary numbers and character encoding
Binary numbers and character encoding: simulation view →

Meaning and mechanism

This is a representation of a number where each digit is a power of 2. With ‘n’ bits, it is possible to represent 2ⁿ patterns, and the range of unsigned integers is from 0 to 2ⁿ−1.

Unicode assigns code points to characters, and UTF-8 encodes those code points as byte sequences. A character does not always occupy one byte.

Relationships and conditions

An unsigned integer is read as N=Σbᵢ2ⁱ. UTF-8 uses 1–4 bytes depending on the code point, so a string’s byte count may differ from its character count.

The units appearing on the screen can be composed of multiple code points. Units with delimiters and integer values use separate interpretation rules than other character encodings.

What to observe in the simulation

The same bits convey different information under different interpretations.

Integers are unsigned 8-bit. UTF-8 encodes the selected Unicode character into actual bytes.

Key relationships and symbols

N = Σbᵢ2ⁱ · count = 2ⁿ

Symbols and units used in the formulas
SymbolMeaningUnit
bᵢi-th bit0 or 1
byteGroup of 8 bits8 bit
Code pointUnicode character identifierInteger identifier

Worked example

Is every UTF-8 character one byte?

It varies by character · The same bits convey different information under different interpretations.

Common misconceptions

  • Knowing only that a bit sequence is 8 bits long does not always identify which character it represents.

Explore this concept through experiments

References

OpenStax · Introduction to Computer Science (English)