MySQL | CONV( ) Function
Last Updated :
21 Nov, 2019
Improve
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:
- number - It is used to specify the number who base needs to be changed.
- current_base - It is used to specify the current base system of the number.
- new_base - It is used to specify the desired base system in which the number needs to be converted.
- MySQL 5.7
- MySQL 5.6
- MySQL 5.5
- MySQL 5.1
- MySQL 5.0
- MySQL 4.1
- MySQL 4.0
- MySQL 3.23
SELECT CONV(20, 10, 2);Output:
10100Example-2: Implementing CONV() function to convert a number from numeric base system 2 to numeric base system 10.
SELECT CONV(10100, 2, 10);Output:
20Example-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:
18446744073709551610Example-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