Bitwise Hamming distance

### 4.3.2 Bitwise Hamming distance

The Hamming distance between two integers is the number of differences between the bits of the two integers. The hamdist command finds the Hamming distance between two integers.

- hamdist takes two arguments: m and n, both integers.
- hamdist(m,n) returns the Hamming distance between m and n.

#### Example

hamdist(0x12,0x38)

or:

hamdist(18,56)

3 |  |  |  |  |  |  |  |  |  |

because 18 is written 0x12 in base 16 and 0b010010 in base 2 and 56 is written 0x38 in base 16 and 0b111000 in base 2, hence hamdist(18,56) is equal to 1+0+1+0+1+0=3.