Quarry School

Encode a character as bytes

Subject: Computing
Level 1 · FoundationsAbout 4 min read
How this was estimated

Programmatic estimate. Rung levels, worked steps, prerequisites, terms and sentence length contribute to this level. It describes the lesson, not your ability.

Reading counts the whole lesson, including folded explanations, at 180 words a minute. Practice allows two minutes per item. These are planning assumptions; take the time you need.

AI estimate unavailable.

Path to here

Open the unit’s lesson list to follow the lesson order.

    Quick review (2 minutes)

    In plain words

    Imagine a coat check.

    Rule

    Capital A has code point U+0041. Its UTF-8 byte is 41. Lowercase é has code point U+00E9. It uses two UTF-8 bytes, C3 first and A9 second.

    A base letter followed by a separate combining accent can use two code points, one for the letter and one for the accent. Together they form a combining sequence. Use the single code point U+00E9 for each é in this lesson's inputs.

    Step

    1. Use UTF-8. Start with an empty row and a byte count of zero. Write one box per byte and two hex digits per box.

    2. Read the input from left to right. For each letter, find its code point in The rule. Add that code point's bytes to the right of the row in the order shown.

    3. Stop once you have written the bytes for the last letter. Read the finished row left to right and count the boxes.

    Trap

    A character count alone leaves the UTF-8 byte count open. AA and Aé each have two letters here. AA takes two bytes, and Aé takes three. Work out how many bytes each code point adds before counting the total.

    1 In plain words

    Imagine a coat check. The clerk gives your coat a number and writes that number on a ticket.

    The letter A is a symbol you can write, called a character. Unicode assigns the character a number called a code point. UTF-8 is an encoding, a rule for writing that number as bytes. A byte is a group of eight bits, each a 0 or a 1.

    Read U+0041 as “Unicode code point zero zero four one.” The number after U+ is written in hexadecimal, or hex, a way to write numbers that uses letters as digits too. On paper, write each byte as a pair of hex digits, so C3 A9 reads “C three, A nine” and shows two bytes. Read the space as a gap between byte labels.

    Remember the order from character to code point to bytes. Use the two entries in The rule to look up the numbers and byte values.

    2 Picture it

    UTF-841AC3A9é

    A is U+0041 and uses byte 41. The single precomposed é is U+00E9 and uses bytes C3 A9. The three bytes in Aé are 41 C3 A9.

    Two code points use three bytes.

    3 Why

    For the letters here, the code point's number tells you how many UTF-8 bytes to write. In base ten, values from 0 through 127 take one byte and values from 128 through 2,047 take two. Capital A has value 65 and lowercase é has value 233, so they fall in different ranges.

    4 The rule

    Capital A has code point U+0041.

    Its UTF-8 byte is 41. Lowercase é has code point U+00E9. It uses two UTF-8 bytes, C3 first and A9 second.

    A base letter followed by a separate combining accent can use two code points, one for the letter and one for the accent. Together they form a combining sequence. Use the single code point U+00E9 for each é in this lesson's inputs.

    5 How

    1. Use UTF-8. Start with an empty row and a byte count of zero. Write one box per byte and two hex digits per box.
    2. Read the input from left to right. For each letter, find its code point in The rule. Add that code point's bytes to the right of the row in the order shown.
    3. Stop once you have written the bytes for the last letter. Read the finished row left to right and count the boxes.

    6 Trace

    Read the UTF-8 bytes for Aé
    CharacterCode pointBytes in hexadecimalByte countExplanation
    AU+0041411Use one byte for this code point.
    éU+00E9C3 A92Use two bytes for this single code point.
    AéU+0041 U+00E941 C3 A93Put the bytes in the same order as their code points.

    7 The trap

    A character count alone leaves the UTF-8 byte count open. AA and Aé each have two letters here. AA takes two bytes, and Aé takes three. Work out how many bytes each code point adds before counting the total.

    Quick checks

    Quick check 1 of 2

    For lowercase é, which is the code point, U+00E9 or C3 A9? How many bytes does it take?

    Show the steps and the answer
    Answer

    U+00E9 is the code point. C3 A9 is two UTF-8 bytes.

    Why: U+ introduces the Unicode number. C3 and A9 each label one byte.

    Source: Python Software Foundation, Python 3.13 Unicode HOWTO

    Quick check 2 of 2

    Write the UTF-8 bytes for éAé in order. How many bytes are there?

    Show the steps and the answer
    Answer

    C3 A9 41 C3 A9 is five UTF-8 bytes.

    Why: The first é adds two bytes, A adds one, and the last é adds two more.

    Source: University of Canterbury, Computer Science Field Guide: Text

    Sources

    1. Python 3.13 Unicode HOWTO. Python Software Foundation. Python Software Foundation License Version 2. Read 25 Nov 2026.
    2. Computer Science Field Guide: Text. University of Canterbury. CC BY-SA 4.0. Read 25 Nov 2026.