-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Add bitCount function #8702
Copy link
Copy link
Closed
Labels
Description
Feature request
I request to add a new bitCount(a) function that should calculate the number of set bits in the supplied integer number (UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64).
Use case
In my project there is a scenario when I need to calculate hamming distance on binary representation of a number (for perceptual hashing), which can be expressed as bitCount(bitXor(A, B)). bitXor has already been implemented, so it would be nice to implement bitCount as well.
Implementation
bitCount function can be implemented with popcnt machine instruction when it is available or with hand-written efficient approach stated here: https://en.wikipedia.org/wiki/Hamming_weight
Reactions are currently unavailable