Calculate logarithm base 2 (binary logarithm). Essential for computer science, information theory, and binary calculations.
log₂(x) answers: "2 raised to what power equals x?"
The binary logarithm (log₂) answers the question: "2 raised to what power equals x?"
Using the change of base formula:
| x | log₂(x) |
|---|---|
| 1 | 0 |
| 2 | 1 |
| 4 | 2 |
| 8 | 3 |
| 16 | 4 |
| 32 | 5 |
| 64 | 6 |
| 128 | 7 |
| 256 | 8 |
| 512 | 9 |
| 1024 | 10 |
For example, to represent 100 different values, you need ⌈log₂(100)⌉ = 7 bits.
Binary search has O(log₂ n) time complexity, meaning each step halves the search space.
A balanced binary tree with n nodes has height ≈ log₂(n).
Log base 2 is fundamental to information theory. The entropy (information content) is measured in bits: