Created
August 6, 2017 05:15
-
-
Save rogerpoon/fdb8a3317e20f8c110eb1e43ed5adafa to your computer and use it in GitHub Desktop.
Fast C++ Bitwise Hamming Distance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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