Open In App

MySQL | CONV( ) Function

The MySQL CONV() function is used for converting a number from one numeric base system to another. The value returned by the CONV() function is in the form of a string value. It accepts three parameters which are the value to be converted, the current numeric base system and the numeric base system to which the value needs to be converted.

The CONV() function treats a number as an unsigned number if a positive value is specified for the new base whereas, the CONV() function treats a number as a signed number if a negative new base is specified.



Syntax:

CONV(number, current_base, new_base)

Parameters Used:



Return Value:
The MySQL CONV() function returns a value in the desired base system specified by the user.

Supported Versions of MySQL:

Example-1: Implementing CONV() function to convert a number from numeric base system 10 to numeric base system 2.

SELECT CONV(20, 10, 2); 

Output:

10100 

Example-2: Implementing CONV() function to convert a number from numeric base system 2 to numeric base system 10.

SELECT CONV(10100, 2, 10); 

Output:

20 

Example-3: Implementing CONV() function to convert a negative number from numeric base system 8 to numeric base system 10.

SELECT CONV(-6, 8, 10); 

Output:

18446744073709551610 

Example-4: Implementing CONV() function to convert a number from numeric base system 16 to numeric base system 10.

SELECT CONV('8D', 16, 10); 

Output:

141 
Article Tags :
SQL