Nearest-neighbor decoding for Hamming codes is a very tedious process. We'll develop a different (more mathematical) approach here, using binary arithmetic.

Regular decimal numbers can be viewed as sequences of digits, where the digits are chosen from the set {0,1,2,3,4,5,6,7,8,9}. And each digit in a number gets multiplied by a different power of 10 to make up the number, as in:

4295 = 4 ^{.} 1000 + 2 ^{.} 100 + 9 ^{.} 10 +
5 ^{.} 1

= 4 ^{.} 10^{3} + 2 ^{.} 10^{2} +
9 ^{.} 10^{1} + 5 ^{.} 10^{0}.

Binary numbers work pretty much the same way, except the digits are chosen from the set {0,1} and each digit gets multiplied by a different power of 2. So the binary number 101001 would stand for:

101001 = 1 ^{.} 2^{5} + 0 ^{.} 2^{4} +
1 ^{.} 2^{3} + 0 ^{.} 2^{2} +
0 ^{.} 2^{1} + 1 ^{.} 2^{0}

= 32 + 8 + 1 = 41_{10}.

Here's a table of the three-digit binary numbers and their decimal equivalents:

Decimal | Binary |

0 | 000 |

1 | 001 |

2 | 010 |

3 | 011 |

4 | 100 |

5 | 101 |

6 | 110 |

7 | 111 |

Sometimes we use subscripts so that we're certain of what number system
we're using, since 11_{10} is eleven, but 11_{2} is three.

*Exercise*: What are the following numbers? 1110_{2} and
101010_{2}

Math mod 2 is arithmetic with just the two numbers 0 and 1. We'll only worry about addition and multiplication (although subtraction and division are possible, too). Multiplication is simple -- it works just the same as ordinary multiplication of the numbers 0 and 1. Here's the whole times table for mod 2:

x | 0 | 1 |

0 | 0 | 0 |

1 | 0 | 1 |

Addition is a little peculiar (but it's not so bad if you think of 0 as being "even" and 1 as being "odd", or XOR:

+ | 0 | 1 |

0 | 0 | 1 |

1 | 1 | 0 |

In addition mod 2, if you have a long addition problem like

1 + 1 + 0 + 1 + 0 + 1 + 1

the answer is 0 if there are an even number of 1's and 1 if there are an
odd number of 1's.