Function Reference

CONV

Converts a number from one numeral system to another.

MySQL 8.1
CONV(num, from_base, to_base)

Parameters

numVARCHAR
Number or string with a number in the source system, for example 'ff'
from_baseINT
Source base, from 2 to 36
to_baseINT
Base of the result, from 2 to 36; a negative one gives a signed number

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.1
SELECT CONV('ff', 16, 10) AS from_hex,
	CONV(255, 10, 2) AS to_binary,
	CONV(255, 10, 16) AS to_hex;
from_hexto_binaryto_hex
25511111111FF

Product ids in binary

MySQL 8.1
SELECT good_id,
	CONV(good_id, 10, 2) AS binary_id
FROM Goods
LIMIT 5;
good_idbinary_id
11
210
311
4100
5101

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.

See also