Skip to content

LOG2

  • x: This parameter represents the numeric expression to calculate the binary logarithm of. It takes a positive number to perform the LOG2 operation. If the value of X is NULL, the function returns NULL. If the value of X is less than or equal to zero, an error will occur.
SELECT LOG2(8) AS Log_Base_2;
+-------------+
| Log_Base_2 |
+-------------+
| 3 |
+-------------+

The LOG2 function in MySQL is used to calculate the base 2 logarithm of a number. In the above example, LOG2(8) returns ‘3’ because the base-2 logarithm of 8 is 3.