CONV
Converts a number from one numeral system to another.
MySQL 8.4
CONV(num, from_base, to_base)- num
- Number or string with a number in the source system, for example 'ff'VARCHAR
- from_base
- Source base, from 2 to 36INT
- to_base
- Base of the result, from 2 to 36; a negative one gives a signed numberINT
Return value
A string with the number in the new system; NULL if a base is out of range
Examples
Hexadecimal and binary notation
MySQL 8.4
SELECT CONV('ff', 16, 10) AS from_hex,
CONV(255, 10, 2) AS to_binary,
CONV(255, 10, 16) AS to_hex;Product ids in binary
MySQL 8.4
SELECT good_id,
CONV(good_id, 10, 2) AS binary_id
FROM Goods
LIMIT 5;Details
Digits above 9 are written as letters: A is 10, Z is 35. A negative number with a positive to_base is treated as an unsigned 64-bit number: CONV(-1, 10, 16) returns FFFFFFFFFFFFFFFF. To keep the sign, give a negative to_base: CONV(-255, 10, -16) returns -FF.