There was an error while loading. Please reload this page.
1 parent 3f882bd commit e41ed9eCopy full SHA for e41ed9e
1 file changed
Bit-Manipulation/LogTwo.js
@@ -1,7 +1,9 @@
1
-/*
2
- Approximate log2 using only bitwise operators
3
-*/
4
-
+/**
+ * https://handwiki.org/wiki/Binary_logarithm
+ * Approximate log2 using only bitwise operators
+ * @param {number} n
5
+ * @returns {number} Log2 approximation equal to floor(log2(n))
6
+ */
7
export const logTwo = (n) => {
8
let result = 0
9
while (n >> 1) {
0 commit comments