## Binary arithmetic

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 . 103 + 2 . 102 + 9 . 101 + 5 . 100.

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 . 25 + 0 . 24 + 1 . 23 + 0 . 22 + 0 . 21 + 1 . 20
= 32 + 8 + 1 = 4110.

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 1110 is eleven, but 112 is three.

Exercise: What are the following numbers? 11102 and 1010102

### Math mod 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.