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:

  • 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.

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

Supported 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-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 



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.