Files
JavaScript/Bit-Manipulation/NextPowerOfTwo.js
2021-10-11 20:13:36 +03:00

16 lines
218 B
JavaScript

/**
*
* This script will find next power of two
* of given number.
*
*/
export const nextPowerOfTwo = (n) => {
let result = 1
while (n > 0) {
result = result << 1
n = n >> 1
}
return result
}