Quarry School

Split a message into numbered pieces

Subject: Computing
Level 1 · FoundationsAbout 5 min read1 new term
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

    A long freight train blocks a line for a whole day.

    Rule

    To send a message with the card protocol, cut it into pieces of 4 characters from the left, the last piece holding the 1 to 4 characters left over, and number the pieces from 1 to N, where N is the length divided by 4 and rounded up. Every card carries To, From, its number of N and its data.

    Step

    1. Count the characters of the message, spaces and punctuation included.

    2. Count the full groups of 4 characters, and add one more card if any characters are left over: that is N, the number of pieces.

    3. Cut the message into pieces of 4 characters from the left; the last piece takes what is left.

    4. Write one card for each piece, with To, From, its number of N and its data.

    5. Check that joining the data of cards 1 to N in order gives back the message.

    Trap

    Leaving spaces and punctuation out of the count can give the wrong number of pieces: MEET-AT-NOON. counted without its period has 12 characters and gets 3 cards instead of 4. Every character is part of the message.

    Numbering from 0 on some cards and from 1 on others breaks the agreement. The card protocol numbers from 1 to N.

    1 In plain words

    A long freight train blocks a line for a whole day. Split into short trains, it shares the line with others, and the short trains can even take different routes.

    The internet sends data the same way: a message travels as a stream of chunks, each wrapped in a packet with data used for routing and reassembly, as the AP course description puts it. The Field Guide gives the reason: a large message sent whole can hold up other traffic on its route.

    In the card protocol, split the message into pieces of 4 characters, from the left, and number them from 1. The last piece holds whatever is left, from 1 to 4 characters. Every card carries the same total. The size of 4 is this protocol's choice; what matters is that each chunk travels with what is needed to put it back.

    Remember one sentence: cut, number, and write the total on every piece. To look it up, see essential knowledge CSN-1.C.1 and CSN-1.C.2 in the AP Computer Science Principles Course and Exam Description.

    2 Picture it

    PieceDataCharacters1 of 3MEET42 of 3-AT-43 of 3NOON4

    A table of the message MEET-AT-NOON split into three pieces of 4 characters. Piece 1 of 3 holds MEET, piece 2 of 3 holds -AT- and piece 3 of 3 holds NOON. The row for piece 2 is marked.

    The message MEET-AT-NOON in three cards of this unit's card protocol

    3 Why

    The number of pieces is the message length divided by 4, rounded up. MEET-AT-NOON has 12 characters, so it makes exactly 3 pieces; MEET-AT-NOON. has 13, so it makes 4, and the fourth holds only the period.

    Each card is complete on its own. The To and From fields go on every card, because each card may travel separately, by its own path.

    Small pieces are what let different messages share a busy route.

    4 The rule

    To send a message with the card protocol, cut it into pieces of 4 characters from the left, the last piece holding the 1 to 4 characters left over, and number the pieces from 1 to N, where N is the length divided by 4 and rounded up.

    Every card carries To, From, its number of N and its data.

    5 How

    1. Count the characters of the message, spaces and punctuation included.
    2. Count the full groups of 4 characters, and add one more card if any characters are left over: that is N, the number of pieces.
    3. Cut the message into pieces of 4 characters from the left; the last piece takes what is left.
    4. Write one card for each piece, with To, From, its number of N and its data.
    5. Check that joining the data of cards 1 to N in order gives back the message.

    6 Trace

    Split MEET-AT-NOON. into cards by this unit's 4-character rule
    StepPiece and dataCharacters leftExplanation
    count13 characters, so N = 41313 divided by 4 is 3.25, rounded up to 4.
    card 11 of 4: MEET9The first 4 characters. Every card also carries To Kai and From Ana.
    card 22 of 4: -AT-5The next 4.
    card 33 of 4: NOON1The next 4.
    card 44 of 4: .0The last piece holds the one character left.

    7 The trap

    Leaving spaces and punctuation out of the count can give the wrong number of pieces: MEET-AT-NOON. counted without its period has 12 characters and gets 3 cards instead of 4. Every character is part of the message.

    Numbering from 0 on some cards and from 1 on others breaks the agreement. The card protocol numbers from 1 to N.

    Quick checks

    Quick check 1 of 2

    The card protocol of this unit puts at most 4 characters on a card. A message has 10 characters. How many cards does it need, and how many characters does the last card hold?

    Show the steps and the answer
    Answer

    It needs 3 cards, and the last card holds 2 characters.

    Why: By the protocol's 4-character rule, 10 divided by 4 is 2.5, rounded up to 3. The first two cards hold 4 characters each, which leaves 2.

    Source: College Board, AP Computer Science Principles Course and Exam Description

    Quick check 2 of 2

    Why does the internet send a large file as many small packets instead of one big one?

    Show the steps and the answer
    Answer

    A message sent whole would hold up other traffic; small packets share the routes, and each can travel separately.

    Why: The Field Guide compares a whole message to a long freight train that blocks a line; split up, the pieces share it and can take different routes.

    Source: University of Canterbury Computer Science Education Research Group, Computer Science Field Guide: Network Communication Protocols, 16.3 Transport layer protocols - TCP, UDP

    Sources

    1. Computer Science Field Guide: Network Communication Protocols, 16.3 Transport layer protocols - TCP, UDP. University of Canterbury Computer Science Education Research Group. CC BY-SA 4.0. Read 2 Dec 2026.
    2. AP Computer Science Principles Course and Exam Description. College Board. All rights reserved. Read 2 Dec 2026.