Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/next-pow-2
Rounds a nonnegative integer up to a power of 2
https://github.com/mikolalysenko/next-pow-2
Last synced: 2 months ago
JSON representation
Rounds a nonnegative integer up to a power of 2
- Host: GitHub
- URL: https://github.com/mikolalysenko/next-pow-2
- Owner: mikolalysenko
- License: mit
- Created: 2015-06-22T21:01:10.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-22T21:02:16.000Z (over 9 years ago)
- Last Synced: 2024-10-20T14:26:56.532Z (2 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
next-pow-2
==========
Round a nonnegative integer up to the next power of 2.# Example
```javascript
var np2 = require('next-pow-2')for(var i=0; i<=10; ++i) {
console.log(i + ' rounds to ' + np2(i))
}
```#### Output
```
0 rounds to 1
1 rounds to 1
2 rounds to 2
3 rounds to 4
4 rounds to 4
5 rounds to 8
6 rounds to 8
7 rounds to 8
8 rounds to 8
9 rounds to 16
10 rounds to 16
```# Install
```
npm i next-pow-2
```# API
#### `require('next-pow-2')(x)`
Rounds `x` to the next power of 2* `x` is a nonnegative integer less than 2^32
**Returns** the next power of 2 after `x`
# License
(c) 2015 Mikola Lysenko. MIT License