MySQL BIN() Function Examples

Let’s look at some examples of the BIN() function in MySQL. The example shows the SQL query for using BIN function in MySQL.

Query:

SELECT BIN(5); 

Output:

'101'

Query:

SELECT BIN(12)

Output:

'1100'

MySQL BIN() Function

The BIN() function in MySQL converts a decimal number to its binary equivalent.

The BIN() function is equivalent to the CONV() function written in the format CONV(number,10,2). In this format, the CONV() function converts the number ‘number’ from base 10 (decimal) to base 2 (binary).

It is important to note that the BIN() function can only be used with positive integers. If you try to use a negative number or a non-integer value as the input to the BIN() function, MySQL will return an error.

The BIN() function returns a string value, the binary equivalent of the decimal number passed as argument. It returns NULL if the number is NULL.

Similar Reads

Syntax

MySQL BIN() function Syntax is:...

MySQL BIN() Function Examples

Let’s look at some examples of the BIN() function in MySQL. The example shows the SQL query for using BIN function in MySQL....

Contact Us