npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

count-trailing-zeros

v1.0.1

Published

Counts the number of trailing zeros of a binary integer

Downloads

1,730

Readme

count-trailing-zeros

Counts the number of trailing zeros for an integer in binary.

Example

var ctz = require('count-trailing-zeros')

for(var i=1; i<=16; ++i) {
  console.log(i+' (bin '+i.toString(2)+') has '+ctz(i)+' trailing zeros')
}

Output

1 (bin 1) has 0 trailing zeros
2 (bin 10) has 1 trailing zeros
3 (bin 11) has 0 trailing zeros
4 (bin 100) has 2 trailing zeros
5 (bin 101) has 0 trailing zeros
6 (bin 110) has 1 trailing zeros
7 (bin 111) has 0 trailing zeros
8 (bin 1000) has 3 trailing zeros
9 (bin 1001) has 0 trailing zeros
10 (bin 1010) has 1 trailing zeros
11 (bin 1011) has 0 trailing zeros
12 (bin 1100) has 2 trailing zeros
13 (bin 1101) has 0 trailing zeros
14 (bin 1110) has 1 trailing zeros
15 (bin 1111) has 0 trailing zeros
16 (bin 10000) has 4 trailing zeros

Install

npm i count-trailing-zeros

API

require('count-trailing-zeros')(v)

Count the number of trailing zeros.

  • v is an integer

Returns The number of trailing zeros of v

Note For a full balanced binary tree with 2^n elements arranged in order, this is the trailing zeros the index of an element is the same as its height in the tree.

License

(c) 2015 Mikola Lysenko. MIT License