Skip to content
Related Articles

Related Articles

MySQL | CONV( ) Function
  • Last Updated : 21 Nov, 2019

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 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :