Skip to main content

LOG2

Calculates the base-2 logarithm of a given number, returning the power to which the number 2 must be raised to obtain the value.

See also:
[SELECT]


Syntax​

SELECT LOG2(numeric_expression) FROM <multipartIdentifier>;

Arguments​

numeric_expression
A positive numeric expression for which the base-2 logarithm is to be calculated.

Return Value(s)​

Returns the base-2 logarithm of the specified numeric value.


Examples​

Calculate the base-2 logarithm of 16​

SELECT LOG2(16) AS log_result;

This query returns 4, as (2^4 = 16).

Calculate the base-2 logarithm of 32​

SELECT LOG2(32) AS log_result;

This query calculates the base-2 logarithm of 32, resulting in 5, since (2^5 = 32).