MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB BIN() Function



The MariaDB BIN() function converts a decimal number to a binary number and returns the result as a string value.

The BIN() function is equivalent to using the CONV() function with CONV(number, 10, 2) syntax.

Syntax

BIN(number)

Parameters

number Required. Specify the number to convert to a binary representation.

Return Value

Returns the binary representation of a decimal number.

Example 1:

The example below shows the usage of BIN() function.

SELECT BIN(1);
Result: '1'

SELECT BIN(2);
Result: '10'

SELECT BIN(10);
Result: '1010'

SELECT BIN(128);
Result: '10000000'

SELECT BIN(200);
Result: '11001000'

SELECT BIN(1024);
Result: '10000000000'

Example 2:

Consider a database table called Sample with the following records:

Datax
Data 110
Data 220
Data 330
Data 440
Data 550

The statement given below can be used to get the binary representation of values of column x.

SELECT *, BIN(x) AS BIN_Value FROM Sample;

This will produce the result as shown below:

DataxBIN_Value
Data 1101010
Data 22010100
Data 33011110
Data 440101000
Data 550110010

❮ MariaDB Functions