QR Code Data Structures
Reed-Solomon error correction levels (L, M, Q, H) and byte encoding.
Understanding QR Codes: Data Structures, Coding Formats, and Error Correction
Quick Response (QR) codes are two-dimensional barcodes used for digital payments and website redirection. This article explains the data encoding formats, versions, and Reed-Solomon error correction rules.
1. The Data Encoding Modes of QR Codes
QR codes can store alphanumeric strings, numeric sequences, raw bytes, and Kanji characters. Each mode uses a different encoding efficiency. For instance, Numeric mode stores up to 7,089 characters by packing three digits into 10 bits. Alphanumeric mode stores up to 4,296 characters, while Byte mode (ideal for URLs) stores up to 2,953 bytes, using standard UTF-8 encoding patterns.
2. The Grid Structure and Version Layouts
A QR code grid is composed of modules (black and white squares) arranged in a square. The code version (ranging from 1 to 40) determines the grid size, with Version 1 measuring 21x21 modules and increasing by 4 modules per version up to Version 40 (177x177). Finder patterns (large squares in three corners) help scanners detect the code orientation, while alignment patterns help correct for perspective distortion.
3. Reed-Solomon Error Correction Mechanics
QR codes use Reed-Solomon error correction, which allows scanners to read codes that are dirty, scratched, or partially covered. The standard features four correction levels: L (7% recovery), M (15% recovery), Q (25% recovery), and H (30% recovery). Higher error correction levels add redundant data modules, increasing the grid density but allowing developers to embed custom logos in the center of the QR code.
4. QR Code Scanning Safety and Phishing Prevention
Because QR codes are visual links, they present security risks. Attackers can paste malicious QR codes over legitimate ones (e.g., on public parking meters) to redirect users to phishing sites or trigger malicious downloads. Users should scan QR codes using readers that display the destination URL before opening it, and inspect the domain name for HTTPS and correct spelling.
5. Generating Styled QR Codes Client-Side
A client-side QR generator uses JavaScript libraries to calculate the matrix grid and draw it to an HTML5 Canvas locally. The canvas API allows users to customize foreground/background colors and export the output as a high-resolution PNG or SVG instantly. This local generation is fast, free of limits, and ensures that sensitive scanned data remains confidential.