Skip to content

Commit e41ed9e

Browse files
author
alexander
committed
url
1 parent 3f882bd commit e41ed9e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Bit-Manipulation/LogTwo.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
/*
2-
Approximate log2 using only bitwise operators
3-
*/
4-
1+
/**
2+
* https://handwiki.org/wiki/Binary_logarithm
3+
* Approximate log2 using only bitwise operators
4+
* @param {number} n
5+
* @returns {number} Log2 approximation equal to floor(log2(n))
6+
*/
57
export const logTwo = (n) => {
68
let result = 0
79
while (n >> 1) {

0 commit comments

Comments
 (0)