# count-trailing-zeros

> Counts the number of trailing zeros of a binary integer

Latest version **1.0.1** (published 2015-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install count-trailing-zeros
pnpm add count-trailing-zeros
yarn add count-trailing-zeros
bun add count-trailing-zeros
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-06-22 |
| First published | 2015-06-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Mikola Lysenko |
| Maintainers | mikolalysenko |
| Keywords | count, trailing, zeros, ctz, bit, twiddle, hack, binary, number, integer, 32, bit |

## Links

- npm: https://www.npmjs.com/package/count-trailing-zeros
- Repository: https://github.com/mikolalysenko/count-trailing-zeros
- Issues: https://github.com/mikolalysenko/count-trailing-zeros/issues
- npm.io page: https://npm.io/package/count-trailing-zeros

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-06-22
- 1.0.0 — 2015-06-22

## README

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

# Example

```javascript
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

---
_Source: https://npm.io/package/count-trailing-zeros · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
