Spec & internals
Encode HELLO WORLD by hand — a complete worked example
HELLO WORLD encodes as an alphanumeric version 1-Q QR code: mode 0010, count 000001011, five character pairs plus a final D, a terminator and pads producing data codewords 20 5B 0B 78 D1 72 DC 4D 43 40 EC 11 EC, then thirteen Reed–Solomon check codewords, placed in a zig-zag and masked.
The setup
The traditional exercise: encode the string HELLO WORLD at error-correction level Q.
Every character is in the
45-character alphanumeric set, and 11 alphanumeric
characters fit comfortably in version 1-Q (capacity: 16), so the target is a 21 × 21
symbol with 13 data codewords and 13 error-correction codewords in a single block.
Every value below is real — you can check each stage against
a decoder at the end.
Step 1: mode and count
- Mode indicator, alphanumeric:
0010 - Character count, 11, in 9 bits (versions 1–9):
000001011
Step 2: encode the characters
Alphanumeric values: H=17, E=14, L=21, O=24, space=36, W=32, R=27, D=13. Characters pair up as 45 × first + second, 11 bits per pair; the odd final character takes 6 bits:
| Pair | Calculation | Value | Bits |
|---|---|---|---|
| H,E | 17 × 45 + 14 | 779 | 01100001011 |
| L,L | 21 × 45 + 21 | 966 | 01111000110 |
| O,␣ | 24 × 45 + 36 | 1116 | 10001011100 |
| W,O | 32 × 45 + 24 | 1464 | 10110111000 |
| R,L | 27 × 45 + 21 | 1236 | 10011010100 |
| D | 13 | 13 | 001101 |
Running total: 4 + 9 + 5 × 11 + 6 = 74 bits.
Step 3: terminator and padding
Version 1-Q holds 13 data codewords = 104 bits, so there is room for the full 4-bit
terminator 0000 (→ 78 bits), then two 0s to reach the 80-bit byte boundary, then the
alternating pad bytes 11101100 00010001 11101100 to fill 104. Slicing the stream into bytes gives the 13 data codewords:
20 5B 0B 78 D1 72 DC 4D 43 40 EC 11 EC
(In decimal: 32, 91, 11, 120, 209, 114, 220, 77, 67, 64, 236, 17, 236.)
Step 4: Reed–Solomon check codewords
Treat the 13 data codewords as polynomial coefficients and divide by the degree-13 generator polynomial over GF(256), as described in Reed–Solomon error correction. The remainder is the 13 check codewords:
A8 48 16 52 D9 36 9C 00 2E 0F B4 7A 10
(Decimal: 168, 72, 22, 82, 217, 54, 156, 0, 46, 15, 180, 122, 16.) The division is mechanical but tedious by hand — 13 rounds of XOR-and-shift using log tables for the GF(256) multiplications. Version 1-Q is a single block, so there is no interleaving: the final sequence is simply data then checks, 26 codewords, 208 bits. Version 1 adds no remainder bits.
Step 5: place, mask, finish
The 208 bits flow into the symbol in the
zig-zag pattern — two-module columns from the
bottom-right, up then down, skipping function patterns. Then the eight
mask patterns are each applied and scored on the four
penalty rules; the winner for this payload
varies by implementation detail, and any choice is valid. Finally the 15-bit
format information for level Q and the chosen mask is
BCH-coded, XORed with 101010000010010, and written twice.
That is a complete QR code, by hand. Generate HELLO WORLD at level Q with
the text tool and you get the same 21 × 21 symbol this arithmetic
produces — decode it and the 26 codewords above come back out.
FAQ
Why is HELLO WORLD the standard QR encoding example?
It is short enough to fit version 1, uses the alphanumeric mode's pairing arithmetic including a space and an odd trailing character, and exercises the terminator and both pad bytes — every interesting encoding rule in one small payload.
What are the data codewords for HELLO WORLD at version 1-Q?
In hex: 20 5B 0B 78 D1 72 DC 4D 43 40 EC 11 EC. The first ten bytes carry the mode header and character data; the last three are the standard pad bytes filling the version's 13-codeword capacity.
How are the error-correction codewords calculated?
By dividing the data codeword polynomial by the degree-13 generator polynomial over GF(256) and taking the remainder: A8 48 16 52 D9 36 9C 00 2E 0F B4 7A 10. Each multiplication uses the field's log and antilog tables.
Which mask does HELLO WORLD use?
Whichever of the eight scores lowest under the encoder's penalty evaluation — implementations can legitimately differ on this, and every choice produces a valid, decodable symbol. The chosen mask number is recorded in the format information.
Try it — free, no signup
Related
- QR code bit stream walkthrough — from text to modules — The full encoding pipeline: mode indicator, character count, data, terminator, pad bytes 0xEC 0x11, Reed–Solomon, interleaving, zig-zag placement, masking.
- Reed–Solomon error correction in QR codes, made readable — QR codes append Reed–Solomon check codewords computed over GF(256). What "recovers 30% damage" really means: erasures count once, unknown errors twice.
- QR code data encoding modes — numeric, alphanumeric, byte, kanji — Numeric packs 3.33 bits per character, alphanumeric 5.5, byte 8, kanji 13. Mode choice is why HTTPS://USEQR.APP makes a smaller code than the lowercase URL.
- Mask selection and penalty scores — how the best mask wins — Encoders score all eight masked symbols on four penalty rules — runs (N1=3), 2×2 blocks (N2=3), finder-lookalikes (N3=40), balance (N4=10) — lowest wins.