JS Built-ins
← Math148 / 215
Mathlog2beginner

Math.log2() β€” log2(4) = 2

πŸ“– Usage Example
// Logarithm base 2
Math.log2(8)    // β†’ 3
Math.log2(256)  // β†’ 8

Use Math.log2() to compute the base-2 logarithm, useful for bit-length calculations and binary algorithms.

Math.log2()

Returns the base-2 logarithm of a number.

Challenge: Verify that Math.log2(4) returns 2.

πŸ’‘ Hints (1)
  • β€’ log2(4) = 2 because 2^2 = 4