The following C function will compute the Hamming distance of two integers (considered as binary values, that is, as sequences of bits). The running time of this procedure is proportional to the Hamming distance rather than to the number of bits in the inputs. It computes the bitwise exclusive or of the two inputs, and then finds the Hamming weight of the result (the number of nonzero bits) using an algorithm of that repeatedly finds and clears the lowest-order nonzero bit. Some compilers support the __builtin_popcount function which can calculate this using specialized processor hardware where available.
The following C function will compute the Hamming distance of two integers (considered as binary values that is as sequences of bits) The running time of this procedure is proportional to the Hamming distance rather than to the number of bits in the inputs It computes the bitwise exclusive or of the two inputs and then finds the Hamming weight of the result (the number of nonzero bits) using an algorithm of that repeatedly finds and clears the lowest-order nonzero bit Some compilers support the __builtin_popcount function which can calculate this using specialized processor hardware where available