Mysql Conv Function

MySQL: CONV Function

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

Description

The MySQL CONV function converts a number from one number base to another and returns the result as a string value.

Syntax

The syntax for the CONV function in MySQL is:

CONV( number, from_base, to_base )

Parameters or Arguments

number

The number to convert.

from_base

The number base that the number is currently represented in. The from_base can be between 2 and 36.

to_base

The number base to convert to. The to_base can be between 2 and 36, or -2 and -36.

Note

  • The CONV function returns the converted number as a string value.
  • If a positive to_base is specified, the CONV function treats number as an unsigned number.
  • If a negative to_base is specified, the CONV function treats number as a signed number.
  • The CONV function with CONV(number,10,2) syntax is equivalent to using the BIN function.
  • The CONV function returns NULL if any of the parameters are NULL (ie: number, from_base, or to_base).

Applies To

The CONV 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, MySQL 3.23

Example

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

For example:

mysql> SELECT CONV(5, 10, 2);
Output: '101'

mysql> SELECT CONV(101, 2, 10);
Output: '5'

mysql> SELECT CONV(74, 10, 16);
Output: '4A'

mysql> SELECT CONV(-74, 10, -16);
Output: '-44

mysql> SELECT CONV('4A', 16, 10);
Output: '74'