Skip to content

Add bitCount function #8702

@ikopylov

Description

@ikopylov

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions