MySQL: LOG2 Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL LOG2 Function

This MySQL 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 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 :

  • 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 LOG2 function examples and explore how to use the LOG2 function.

For example:

mysql> SELECT LOG2(1);
Result: 0

mysql> SELECT LOG2(8);
Result: 3

mysql> SELECT LOG2(1024);
Result: 10

mysql> SELECT LOG2(0);
Result: NULL

Next Topic : Click Here

This Post Has One Comment

Leave a Reply