Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Character Encodings  ›  Lesson

Unicode — A Number for Every Character

Unicode 12 minUnicode assigns every character in every writing system a unique number called a code point, written U+ followed by hex, separately from how those numbers are turned into bytes.

Unicode — A Number for Every Character

In the 1990s an email from Moscow to Delhi often arrived as gibberish. Every region had its own way to squeeze its alphabet into 256 byte values, and the same byte meant different letters in each. Unicode fixed this by giving up on squeezing: it gives every character in every script its own number, once, for everyone.

The rule

Unicode gives every character one number, its code point, written U+hex.

A code point is written U+ followed by at least four hex digits:

Character Code point Decimal
A U+0041 65
é U+00E9 233
अ U+0905 2,309
₹ U+20B9 8,377
😀 U+1F600 128,512

Three facts to hold on to:

  • The first 128 code points are ASCII. U+0041 is A, exactly as in ASCII, so ASCII text is already valid Unicode.
  • The space runs from U+0000 to U+10FFFF, room for 1,114,112 code points. Most are still unassigned.
  • A code point is a number, not bytes. How the number is written to memory or a file is a separate choice, called an encoding (UTF-8, UTF-16, UTF-32). The same text can be encoded different ways.

One more subtlety: what a reader sees as one character is not always one code point. é can be the single code point U+00E9, or e followed by a combining accent U+0301. Many emoji, including most flags and family emoji, are several code points joined together. So "string length" depends on what you count.

The shortcut

Keep two layers apart in your head: character → code point (Unicode's job), then code point → bytes (the encoding's job). Whenever text looks wrong, ask which layer broke.

Following the rupee sign ₹ through both layersStep 1 of 4
  1. Character to code point

    Unicode says ₹ is U+20B9.

Drills

Answer fast — trust the rule.

quick drill

What character is U+0041?

quick drill

What is the highest code point Unicode allows?

quick drill

Which statement is true?

quick drill

Why might a program report a length of 2 for what looks like the single character é?

Remember

  • Unicode gives every character one code point, written U+hex, from U+0000 to U+10FFFF.
  • The first 128 code points are ASCII.
  • The trap: a code point is not bytes, and one visible character can be several code points.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainCharacters are not bytes

Explain the difference between a Unicode code point and an encoding, using 'A' (U+0041) and the emoji 😀 (U+1F600) as examples. Then explain why a string that looks like one character on screen can have a length of 2.