MySQL BIN() Function
The BIN()
function in MySQL converts a decimal number into its binary (base-2) equivalent. This is a very useful function when you're working with binary data or need to represent numbers in a binary format.
BIN(): Definition and Usage
BIN()
takes a decimal number as input and returns a string that represents that number in binary format (using only 0s and 1s). This is helpful for tasks involving binary data or for displaying numbers in a different numerical system.
Syntax
Syntax
BIN(number)
Parameter Values
Parameter | Description |
---|---|
number |
The decimal number you want to convert to binary. This is required. |
Examples
Converting a Decimal Number to Binary
This example converts the decimal number 15 to its binary representation.
Syntax
SELECT BIN(15);
Output
1111
Converting Other Decimal Numbers to Binary
These examples show the binary equivalents of 111 and 8.
Syntax
SELECT BIN(111);
SELECT BIN(8);
Output
1101111
1000