MySQL LOG2() Function
The LOG2()
function in MySQL calculates the base-2 logarithm of a number. In other words, it determines the power to which you must raise 2 to obtain the given number.
LOG2(): Definition and Usage
Base-2 logarithms are particularly useful in computer science and fields dealing with binary data, as they directly relate to the number of bits required to represent a value. They are also helpful in various mathematical and scientific computations.
Related Function
For natural logarithms (base *e*) and logarithms to other bases, see the LOG()
function.
Syntax
Syntax
LOG2(number)
Parameter Values
Parameter | Description |
---|---|
number |
The number for which you want to calculate the base-2 logarithm. This must be greater than 0. This is required. |
Examples
Base-2 Logarithm of 6
This example calculates log2(6).
Syntax
SELECT LOG2(6);
Output
2.58496250072116
Base-2 Logarithm of 64
Calculating log2(64).
Syntax
SELECT LOG2(64);
Output
6