QR Code Character Encoding |
QR Code Encoding
The method by which the characters are converted into bits of data and stored in a QR code
- There are four standard encoding modes used by QR codes: numeric, alphanumeric, binary and kanji.
- This tool demonstrates numeric, alphanumeric and binary encoding.
- All characters can be encoded using binary encoding although this may not be the most efficient selection.
- The selected encoding is stored as a 4-bit mode indicator at the beginning of the data.
Table of encoding types for a QR code
| Encoding | Description | 4-bit Mode Indicator |
|---|---|---|
| Numeric | Numeric characters: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 | 0001 |
| Alphanumeric | Uppercase letters, numeric characters, space or one of the characters $ % * + - , / | 0010 |
| Binary | Any character. | 0100 |
| Kanji | Kanji characters | 1000 |
Numeric Encoding
Numeric encoding can be used if the data is made up entirely of the characters 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9
Encoding the Data
To encode the numeric characters:
- The digits are placed into groups of three from left to right to create values between 0 and 999.
- The 3-digit values are coverted to 10-bit binary numbers.
- If there is one remaining digit, it is multiplied by 16 and converted to an 8-bit binary number
- If there are two remaining digits, 2-digit value is multiplied by 2. The result is converted to an 8-bit binary number
Example: 12345
Digit groups: 123 45
Calculation for 123
- 123 = 0001111011 (10-bit binary value)
Calculation for 45
- 45 × 2 = 90
- 90 = 01011010 (8-bit binary value)
Example: 9876543
Digit groups: 987, 654 and 3
Calculation for 987
- 987 = 1111011011 (10-bit binary value)
Calculation for 654
- 654 = 1010001110 (10-bit binary value)
Calculation for 3
- 3 × 16 = 48
- 48 = 00110000 (8-bit binary value)
Alphanumeric Encoding
Alphanumeric encoding can be used if the data is made up entirely of the following:
- Numeric digits
- Upper case letters
- Space
- The characters $ % * + - , / .
| ASCII value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|---|
| Character | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| ASCII value | 9 | A | B | C | D | E | F | G | H |
| Character | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| ASCII value | I | J | K | L | M | N | O | P | Q |
| Character | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| ASCII value | R | S | T | U | V | W | X | Y | Z |
| Character | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
| ASCII value | $ | % | * | + | - | . | / | : | |
| Character | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
Encoding the Data
To encode the alphanumeric characters:
- Look up the value of each alphanumeric character.
- The values are taken in pairs.
- The first value of each pair is multiplied by 45 and added to the second value to form a value between 1 and 2024.
- This value is then converted to an 11-bit binary number.
- If there is one remaining character, its value is multiplied by 4 and converted to an 8-bit binary number.
Example: CAT
Character groups: CA T
Calculation for C and A
- The values for C and A are 12 and 10
- 45 × 12 + 10 = 550
- 550 = 01000100110 (11-bit binary value)
Calculation for T
- The value for T is 29
- 4 × 29 = 29
- 29 = 01110100 (8-bit binary value)
Binary Encoding
Binary encoding can be used for any character that has a unicode value and is stored using one of more bytes using UTF-8 encoding.
For values between 0 and 127, one byte of data is used and the character is encoded using it's ASCII value.
| ASCII value | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Character |
