MySQL CONV() Function

In MySQL, the CONV() function converts a number from one number base to another, such as from base 10 to base 2.

CONV() Syntax

Here is the syntax of the MySQL CONV() function:

CONV(num, from_base, to_base)

Parameters

num
Required. A number.
from_base
Required. The number base used by num. From 2 to 36.
to_base
Required. The number base to convert to. From 2 to 36.

Return value

The MySQL CONV() function convert numbers from one number base to another.

The CONV() function will return NULL if any parameter is NULL.

CONV() Examples

This example converts several hexadecimal characters to decimal numbers:

SELECT 
    CONV('A', 16, 10),
    CONV('B', 16, 10),
    CONV('C', 16, 10),
    CONV('D', 16, 10),
    CONV('E', 16, 10),
    CONV('F', 16, 10)\G
*************************** 1\. row ***************************
CONV('A', 16, 10): 10
CONV('B', 16, 10): 11
CONV('C', 16, 10): 12
CONV('D', 16, 10): 13
CONV('E', 16, 10): 14
CONV('F', 16, 10): 15

This example converts several numbers in base 10 to numbers in base 2:

SELECT 
    CONV(16, 10, 2),
    CONV(32, 10, 2),
    CONV(64, 10, 2)\G
*************************** 1\. row ***************************
CONV(16, 10, 2): 10000
CONV(32, 10, 2): 100000
CONV(64, 10, 2): 1000000