$$
\begin{array}{c} \begin{array} { r l } { \mathrm { d } \hat { \mathbf { u } } \oplus } & { \stackrel { \mathrm { d e f } } { = } \frac { \boldsymbol { u } } { \mathrm { d } z } \le \boldsymbol { g } \le \boldsymbol { g } } \\ { \mathrm { u b l i d } } & { \stackrel { \mathrm { R e l } } { = } \left\{ \begin{array} { l l } { \hat { \mathbf { u } } } & { \hat { \mathbf { u } } } \\ { \hat { \mathbf { u } } \oplus \hat { \mathbf { u } } \oplus \hat { \mathbf { x } } } \\ { \hat { \mathbf { u } } \oplus \hat { \mathbf { u } } } \end{array} \right. } \\ { \mathrm { c o n d ~ i n d a t i } } \\ { \mathrm { d e t ~ t h e t i n t } } \\ { \mathrm { d e t ~ t h e t i n t } } \\ { \mathrm { c o s e ~ t i m i t i n g } } \\ { \mathrm { d e t ~ t h e t i n t } } \\ { \mathrm { d e t ~ t h e t i n t } } \\ { \mathrm { d e t ~ t h e t i n t } } \end{array} \} , \quad & { \hat { \mathbf { u } } \oplus \hat { \mathbf { u } } \oplus \hat { \mathbf { v } } \oplus \hat { \mathbf { u } } } \\ { \mathrm { d } \hat { \mathbf { u } } \oplus \hat { \mathbf { u } } \oplus \hat { \mathbf { v } } \oplus \hat { \mathbf { u } } } \\ { \mathrm { d } \hat { \mathbf { u } } \oplus \hat { \mathbf { u } } \oplus \hat { \mathbf { v } } \oplus \hat { \mathbf { u } } } \\ { \mathrm { d } \hat { \mathbf { u } } \oplus \hat { \mathbf { u } } \oplus \hat { \mathbf { v } } \oplus \hat { \mathbf { u } } } \\ { \mathrm { d } \hat { \mathbf { u } } \oplus \hat { \mathbf { v } } \oplus \hat { \mathbf { u } } } \end{array}
$$
中间护线后面仍然是6组比特串,每组中含有7个比特位。之后是最右边的护线,最右边的护线通常都为101。最右边的护线可以实现UPC的反向扫描(也就是从右到左扫描),这一点我们将在后面解释。
因此,整个UPC对12个数字进行了编码。UPC的左边含有6个编码数字,每个数字占有7个比特位。你可以利用如下的表格来解码。
左边的编码
$$
\begin{array} { r l r l } & { 0 0 1 1 0 1 = 0 } & & { 0 1 1 0 0 0 1 = 5 } \\ & { 0 0 1 1 0 0 1 = 1 } & & { 0 1 0 1 1 1 = 6 } \\ & { 0 0 1 0 0 1 1 = 2 } & & { 0 1 1 0 1 1 = 7 } \\ & { 0 1 1 1 1 0 1 = 3 } & & { 0 1 1 0 1 1 1 = 8 } \\ & { 0 1 0 0 0 1 1 = 4 } & & { 0 0 0 1 0 1 1 = 9 } \end{array}
$$
注意,这里每个7位编码都是以0开头,以1结尾的。如果扫描仪遇到了一个位于左边的7位编码,这个编码是以1开头以0结尾的,那么它就知道自已没有将UPC正确地读入或者条形码被篡改了。另外我们还注意到每组编码都仅有两组连续为1的比特位,这就暗示每个数字对应着UPC码中的两个垂直条纹。
你也会发现,上表中每组编码都含有奇数个1。这是另一种检查错误和一致性的方法,称为奇偶校验。如果一组比特位中含有偶数个1,它就称为偶校验;如果含有奇数个1,那么它就称为奇校验。这样看来,所有这些编码都拥有奇校验。
编码隐匿在计算机软硬件背后的语言
84