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

MySQLMySQLi Database

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.

raja
Published on 20-Feb-2018 07:16:40
Advertisements