TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Returns the Hamming distance between two integers. More...
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | bit_manipulation |
for assert | |
namespace | hamming_distance |
Functions for Hamming distance implementation. | |
Functions | |
uint64_t | bit_manipulation::hamming_distance::bitCount (uint64_t value) |
uint64_t | bit_manipulation::hamming_distance::hamming_distance (uint64_t a, uint64_t b) |
uint64_t | bit_manipulation::hamming_distance::hamming_distance (const std::string &a, const std::string &b) |
static void | test () |
Function to the test hamming distance. | |
int | main () |
Main function. | |
Returns the Hamming distance between two integers.
To find hamming distance between two integers, we take their xor, which will have a set bit iff those bits differ in the two numbers. Hence, we return the number of such set bits.
Definition in file hamming_distance.cpp.
uint64_t bit_manipulation::hamming_distance::bitCount | ( | uint64_t | value | ) |
This function returns the number of set bits in the given number.
value | the number of which we want to count the number of set bits. |
Definition at line 35 of file hamming_distance.cpp.
uint64_t bit_manipulation::hamming_distance::hamming_distance | ( | const std::string & | a, |
const std::string & | b ) |
This function returns the hamming distance between two strings.
a | the first string |
b | the second string |
Definition at line 60 of file hamming_distance.cpp.
uint64_t bit_manipulation::hamming_distance::hamming_distance | ( | uint64_t | a, |
uint64_t | b ) |
This function returns the hamming distance between two integers.
a | the first number |
b | the second number |
Definition at line 52 of file hamming_distance.cpp.
int main | ( | void | ) |
Main function.
Definition at line 100 of file hamming_distance.cpp.
|
static |
Function to the test hamming distance.
Definition at line 76 of file hamming_distance.cpp.