Skip to content

Instantly share code, notes, and snippets.

@rogerpoon
Created August 6, 2017 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerpoon/fdb8a3317e20f8c110eb1e43ed5adafa to your computer and use it in GitHub Desktop.
Save rogerpoon/fdb8a3317e20f8c110eb1e43ed5adafa to your computer and use it in GitHub Desktop.
Fast C++ Bitwise Hamming Distance
#include <bitset>
#include <cassert>
#include <cstdint>
int main() {
const uint64_t a = 3, b = 5;
const size_t diff = a ^ b;
std::bitset<64> diff_bits(diff);
assert(diff_bits.count() == 2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment