Han Xin code


Han Xin code is two-dimensional matrix barcode symbology invented in 2007 by Chinese company The Article Numbering Center of China to break the monopoly of QR code. As a QR code, Han Xin code consists of black squares and white square spaces arranged in a square grid on a white background. It has four finder patterns and other markers which allow to recognize it with camera-based readers. Han Xin code contains Reed–Solomon error correction with ability to read corrupted images. At this time, it is issued as ISO/IEC 20830:2021.
The main advantage, comparable to QR code, is an embedded ability to natively encode Chinese characters instead of Japanese in QR code. Han Xin code in maximal 84 version allows to encode 7827 numeric characters, 4350 English text characters, 3261 bytes and 1044–2174 Chinese characters. Han Xin code encodes full ISO/IEC 646 Latin characters instead of restricted amount Latin characters which is supported by QR code. It makes Han Xin code more suitable for English text encoding or GS1 Application Identifiers data encoding.
Additionally, Han Xin code can encode Unicode characters from other languages with special Unicode mode, which has embedded lossless compression for UTF-8 characters set and Extended Channel Interpretation support. Han Xin code has special compactification mode for URI encoding and can reduce barcode size which encodes links to web pages.

History and standards

The Article Numbering Center of China started research during the 10th Five-year plans of China of a home-grown QR code replacement to replace QR codes, which were considered a Japanese monopoly in 2D barcodes. In 2007, the new barcodes standard, at this time known as Han Xin code, was published as GB/T 21049-2007 with the name Chinese-sensible code.
In 2011, USA company Association for Automatic Identification and Mobility brought out ISS Han Xin Code symbology as official encoding standard and published it in the own store.
In 2015, the ISO/IEC JTC 1/SC 31 group started implementation of Han Xin code as an international standard and published it as ISO/IEC 20830:2021 in 2021.
In 2022, the Chinese-sensible code standard was reviewed as GB/T 21049-2022 and renamed as Han Xin code to be compliant with ISO standard.
The following patents relating to Han Xin code encoding and decoding are registered in Europe and the United States:
  • European Patent Office EP3330887B1 by Fujian Landi Commercial Equipment Co Ltd "Chinese-sensitive code feature pattern detection method and system"
  • United States Patent US10095903B2 by Ingenico Fujian Technology Co Ltd "Block decoding method and system for two-dimensional code"
  • United States Patent US10528781B2 by Ingenico Fujian Technology Co Ltd "Detection method and system for characteristic patterns of Han Xin codes"

    Application

Han Xin code can be used in the same way as QR code. At this time Han Xin code is used mostly in China, because it has embedded encoding ability to encode Chinese characters. However, most of barcode printers and barcode scanners support Han Xin code. Han Xin code can be scanned on iOS and Android mobile devices and many barcode libraries support reading and writing Han Xin code.
Main advantages of Han Xin code are:
  • ability to encode Chinese characters with embedded methods;
  • Extended Channel Interpretation support;
  • embedded method for compact UTF-8 encoding with embedded lossless compression;
  • embedded method for URI compact encoding;
  • compact GS1 Application Identifiers data encoding comparable to QR code;
  • full ISO/IEC 646 support for compact numeric and text encoding.

    Barcode design

Han Xin code represents data in black and white square modules, where dark module is a binary one and a light module is a zero. Additionally, Han Xin code can be encoded in inverse colors, but this option in many barcode readers is disabled by default. Black and white modules are arranged into square region with sizes from 23 × 23 modules to 189 × 189 modules. As QR code, Han Xin code does not have rectangular versions like DataMatrix has and this restricts usage of Han Xin code in some cases. Han Xin code version size can be calculated with the following formula:
Han Xin code symbol is constructed from the following elements:
  • Quiet Zone – is surrounding the symbol on all four sides with at least 3X size;
  • Finder Pattern – consists from 4 Position Detection Patterns which is placed on all four corners of symbol and used to detect symbol position and area;
  • Alignment Patterns and Assistant Alignment Patterns – is started from Version 4 and helps with the decoding of distorted code;
  • Structural Information Regions – is surrounding all four Finder Patterns and used to encode symbol parameters like version, mask and error correction mode;
  • Data Regions – masked binary data encoded in black and white modules.

    Finder pattern

Finder Pattern consists from four Position Detection Patterns located at the four corners of the barcode. The size of Position Detection Pattern is 7×7 modules and it is constructed from 5 elements: dark 7 × 7 modules, light 6 × 6 modules, dark 5 × 5 modules, light 4 × 4 modules, dark 3 × 3 modules respectively.
The scanning ratio of each Position Detection Pattern is 1:1:1:1:3 or 3:1:1:1:1. The four patterns orientation allows to detect unambiguously the barcode location and orientation.
Every pattern has Position Detection Pattern separator with Structural Information Region aligned to it.

Alignment pattern

The Alignment Patterns are added to the Han Xin code from Version 4 and used to precise cell position in the distorted barcodes. Alignment Patterns in Han Xin code are split into:
  • Alignment Pattern – set of step-wise alignment lines;
  • Assistant Alignment Pattern - 6 modules, including 5 light modules and 1 dark module.
The Alignment Pattern is made up of a dark line and a downside adjacent light line which are one module wide. Assistant Alignment Pattern consisting from 5 light modules and 1 dark module indicates edge of region block with its dark module.
Below you can see examples of Han Xin code with different Alignment pattern placement.

Structural information

Han Xin code Structural Information Region is a one module wide region surrounding the four Position Detection Patterns. Han Xin code has two Structural Information identical arrays, which are made from 34 data modules. Every Structural Information array is split on 17 modules which are placed around each Position Detection Pattern.
Structural Information Region encodes the following data:
  • Version + 20 ;
  • Error correction level ;
  • Mask index ;
  • Error correction Reed–Solomon error correction data ;
  • Bits 28–33 are ignored and can be any.
Metadata bits from 0–11 are split into 4 bits tetrads and supplemented with four error correction tetrads.

Data masking

To make Han Xin code dark and light modules amount to be closely to 1:1 in the symbol, masking algorithm is used. Masking sequence is applied to Data Region through the XOR operation. Finder Pattern, Alignment Patterns and Structural Information Regions are excluded from masking operation. The following table shows mask pattern algorithms.
Condition of masking solutionData mask pattern reference
Non-masking00
mod 2=001
mod 3+) mod 2=010
mod 2=011

i - Row index of the symbol.
j - Column index of the symbol.
Both and start from, the top left corner module of the symbol. When the masking solution condition is true, the resulting mask bit is 1.

Error correction

Han Xin code uses Reed–Solomon error correction. Encoded data is represented as byte array. Data array divided into blocks and error correction codewords sequence is generated for each block which is added to the end of the error correction block. After this, all blocks are merged sequentially into byte stream.
The polynomial arithmetic for Han Xin Code uses finite field generation polynomial: x^8 + x^6 + x^5 + x with initial root = 1.
The amount of error correction codewords depends on symbol version and error correction level and can be from 16% to 60%, which allows to correct from 8% to 30% damage.
Error correction levelRecovery capacity % Encoding of error correction level
L18%00
L215%01
L323%10
L430%11

Data region

Han Xin code data is encoded as byte array. Data byte array is split into error correction blocks, where error correction codewords are added. Error correction blocks are united into one codewords array:
=> +... + =>
As an example, this can be demonstrated on Han Xin code version 5 with error correction level L4. It has 27 encoded codewords and 2 error correction blocks with each block size of data codewords and error correction codewords:, :
=> + => =>
D - Data codewords.
E - error codeword, where b is block number and x position in block.
C - resulted codewords.
As the next operation, resulted codewords array C is split into blocks with size of 13 bytes which connects codewords in the same position of each block and form new codewords array. The result is byte array of the same size but mixed by position of 13.
=> =>
CM – mixed by position of 13 array of codewords.
After the upper operations the resulted codewords are placed into data region row by row from left to right and from up to down. Horizontal line damage would affect fewer codewords, vertical line damage would affect more codewords.

Encoding

Han Xin code can encode 7827 numeric characters, 4350 English text characters, 3261 bytes and 1044–2174 Chinese characters in the maximal version 84 version. Additionally, it supports special Unicode and industrial modes. All modes can be mixed to obtain best compactification level for the data. The following table demonstrates abilities to encode data with different barcode version and error correction level.