@f/popcount

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @f/popcount

Weekly Downloads

23

Version

1.0.0

License

MIT

Last publish

Collaborators

  • f