# Hamming Code Strategy for Medical Image Sharing
## 3 Hamming Codes  
Detecting transmission errors is highly significant in data communication. The simplest technique in detecting an error is to append a parity bit to each byte of the transmitted data. This mechanism detects the occurrence of error correctly if the number of error bits is an odd number. However, it cannot pinpoint the error bit by a byte. Hamming code is superior to parity check because it can detect and identify the location of a single-bit error in the transmitted data [36]. Hamming codes are available in different sizes. If the number of parity bits is \(m\) (\(\geq\)3), then the code length is \(n=2^{m}-1\). Hamming code has a minimum Hamming distance 3, and thus it can correct one single error. For example, for \(m=3\), the code length is 7 bits in which there are three parity bits and four data bits; this code is called (7,4) Hamming code. Similarly, (15,11) Hamming code has four parity bits and eleven data bits. The number of data bits increases exponentially as the number of parity bits grows. The parity-check matrix \(\mathbf{H}\) of Hamming code consists of all non-zero m-tuple \(2^{m}\) as its columns (i.e., \(2^{m}-1\) columns). Suppose that the parity-check matrix is \(\mathbf{H}=[I_{m}Q]\), where \(I_{m}\) is an \(m\times m\) identity matrix and \(\mathbf{Q}\) is an \(m\)-tuple with weight two or more. Then the generator matrix is \(\mathbf{G}=[Q^{T}I_{n-m}]\), where \(\mathbf{G}\times\mathbf{H}^{T}=[0]_{m\times(n-m)}\). In this paper, our approach adopts (7,4) Hamming code and (15,11) Hamming code. The following two examples show how to encode and decode for these two Hamming codes, respectively. **Example 1**. : _For (7,4) Hamming code, \(\mathbf{H}\) is a \(3\times 7\) matrix and \(\mathbf{G}\) is a \(4\times 7\) matrix, as shown below. Obviously, one can easily verify \(\mathbf{G}\times\mathbf{H}^{T}=[0]_{4\times 3}\)._  
\[H=[I_{3}Q]=\left[ \begin{array}{cccccccc}1&0&0&1&1&0&1\\ 0&1&0&1&0&1&1\\ 0&0&1&0&1&1&1\end{array} \right]\]  
\[G=[Q^{T}I_{4}]=\left[ \begin{array}{cccccccc}1&1&0&1&0&0&0\\ 1&0&1&0&1&0&0\\ 0&1&1&0&0&1&0\\ 1&1&1&0&0&0&1\end{array} \right]\]  
The above code is the so-called systematic code, i.e., the 4 data bits (d\({}_{1}\), d\({}_{2}\), d\({}_{3}\) and d\({}_{4}\)) are at the most right 4 bits, and others are parity bits. To encode a 4-bit data \(d=[d_{1}\)\(d_{2}\)\(d_{3}\)\(d_{4}]\) into a 7-bit codeword c, the following equation is applied:  
\[c=d\times G=[p_{1}p_{2}p_{3}d_{1}d_{2}d_{3}d_{4}]. \tag{1}\]From Equation (1), we have \(p_{1}=d_{1}\oplus d_{3}\oplus d_{4}\), \(p_{2}=d_{1}\oplus d_{3}\oplus d_{4}\), and \(p_{3}=d_{2}\oplus d_{3}\oplus d_{4}\). It is observed that there are at least 2 parity bits covering a data bit, so even a parity bit is flipped we still can detect and correct it. For example, suppose that the data is \(d=[0\ 1\ 0\ 1]\), then \(p_{1}=1\), \(p_{2}=1\) and \(p_{3}=0\); the codeword is \(c=[1\ 1\ 0\ 0\ 1\ 0\ 1]\). For decoding, the syndrome, a 3-tuple, is computed as  
\[s=c^{\prime}\times H^{T}=[s_{3}\ s_{2}\ s_{1}]. \tag{2}\]  
\(s=(s_{3},\ s_{2},s_{1})=c^{\prime}\times\mathbf{H}^{T}\). If the syndrome is a zero vector \([0\ 0\ 0]\), the codeword is correct; otherwise, the syndrome \((s_{3}\ s_{2}\ s_{1})\) can be used for correcting one error. For the received word \(c^{\prime}=\) characteristic \([1\ 1\ 1\ 0\ 1\ 0\ 1]\), the syndrome vector \([s_{3}\ s_{2}\ s_{1}]\) equals to \([0\ 0\ 1]\). The 3-tuple \((0\ 0\ 1)\) is the third row in HT, and thus the bit \(p_{3}\) (the position is 3 from left) should be flipped. The correct codeword is \([1\ 1\ 0\ 0\ 1\ 0\ 1]\). **Example 2**. : _The (15,11) Hamming code is constructed in the same manner as the (7,4) Hamming code. The systematic forms of \(4\times 15\) parity-check matrix \(\mathbf{H}\) and \(11\times 15\) generator matrix \(\mathbf{G}\) are shown below._  
\[H=[I_{4}\mathbf{Q}]=\left[ \begin{array}{cccccccccccccccc}1&0&0&0&1&1&0&1&0&0&1& 1&1&0&1\\ 0&1&0&0&1&0&1&0&1&0&1&1&0&1&1\\ 0&0&1&0&0&1&1&0&0&1&1&0&1&1\\ 0&0&0&1&0&0&0&1&1&1&0&1&1&1\\ \end{array}