In MySQL, how can we convert a value from one number system to the value in another number system?


With the help of MySQL CONV() function, a value from one number system can be converted to the other number system.

Syntax

CONV(N, from_base, to_base)

Here, ‘N’ is the number which is to be converted, ‘from_base’ is the current base of that number and ‘to_base’ is the base in which that number has to be converted. ‘N’ is interpreted as an integer but it may be specified as integer or a string.

Example

mysql> Select CONV('10',10,2) AS 'DECIMAL TO BINARY';
+-------------------+
| DECIMAL TO BINARY |
+-------------------+
| 1010              |
+-------------------+
1 row in set (0.00 sec)

In the example above, the numeric value 10 of the decimal number system is converting to the binary number system.

Updated on: 03-Feb-2020

52 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements