1.0.0 • Published 8 years ago

@f/popcount v1.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
8 years ago

popcount

Build status Git tag NPM version Code style

Population count (aka hamming weight) function. Counts the number of set (i.e. 1-valued) bits in a 32-bit integer.

Installation

$ npm install @f/popcount

Usage

var popcount = require('@f/popcount')

popcount(3) === 2
popcount(4) === 1
popcount(0xFF) === 8
popcount(0xFF, 3) === 3

API

popcount(x, n)

  • x - The 32-bit integer who's population you wish to count
  • n - Optional. The bit position to begin the count from. E.g. popcount(x, 8) returns the number of bits set below the 8th bit in x.

Returns: The number of bits set in x below the nth position, if n is specified.

License

MIT