Created
March 16, 2022 07:52
-
-
Save VorticonCmdr/3e2d4af64bdb1d84c415077945585b5f to your computer and use it in GitHub Desktop.
Hamming distance for BigInt
This file contains hidden or 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
function hdist(a, b) { | |
let one = BigInt(1); | |
let d = 0; | |
let h = a ^ b; | |
while (h > 0) { | |
d ++; | |
h &= h - one; | |
} | |
return d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment