LOG2(X) returns the base-2 logarithm of X. It is useful when reasoning about powers of two and bit sizes.
SELECT LOG2(7); -- Output: 2.8073549220576
SELECT LOG2(0.1); -- Output: -3.32192809488736
SELECT LOG2(0); -- Output: NULL
SELECT ROUND(LOG2(8), 2); -- Output: 3.00
SELECT ROUND(LOG2(-5), 2); -- Output: NULL
SELECT ROUND(LOG2(9), 2); -- Output: 3.17
SELECT LOG2(X);
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.