ID EN
Mathematical Functions

LOG2(X)

MySQL 8.4

Returns the base-2 logarithm of X. If X is less than or equal to 0.0E0, the function returns NULL and a warning “Invalid argument for logarithm” is reported. Returns NULL if X is NULL.

Syntax

MYSQL
SELECT LOG2(65536);
16
SELECT LOG2(-100);
NULL

Examples

Example

LOG2() is useful for finding out how many bits a number requires for storage. This function is approximately equivalent to the expression LOG(X) / LOG(2).

MYSQL
SELECT LOG2(65536);
16
SELECT LOG2(-100);
NULL