Mysql Log2 Function

MySQL: LOG2 Function

This tutorial explains how to use the MySQL LOG2 function with syntax and examples.

Description

The MySQL LOG2 function returns the base-2 logarithm of a number.

Syntax

The syntax for the LOG2 function in MySQL is:

LOG2( number )

Parameters or Arguments

number

The number to take the base-2 logarithm of. Must be greater than 0.

Note

  • The LOG2 function will return NULL, if number is less than or equal to 0.
  • See also the LOG function.

Applies To

The LOG2 function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0.3

Example

Let's look at some MySQL LOG2 function examples and explore how to use the LOG2 function in MySQL.

For example:

mysql> SELECT LOG2(1);
Output: 0

mysql> SELECT LOG2(8);
Output: 3

mysql> SELECT LOG2(1024);
Output: 10

mysql> SELECT LOG2(0);
Output: NULL