🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

next-pow-2

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-pow-2

Rounds an integer up to a power of 2

1.0.0
latest
Source
npm
Version published
Weekly downloads
5.7K
-0.42%
Maintainers
1
Weekly downloads
 
Created
Source

next-pow-2

Round a nonnegative integer up to the next power of 2.

Example

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

Keywords

next

FAQs

Package last updated on 22 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts