Home ยป BIN Function in SQL

BIN Function in SQL

by Online Tutorials Library

BIN Function in SQL

The BIN is a SQL function which converts the given decimal number to its binary equivalent. This function return NULL, if the NULL is passed in the function.

Syntax of BIN Function

In the BIN syntax, we have to pass that decimal number whose binary equivalent we want to find.

In the Structured Query Language, we can also use the BIN function with the column of the table as shown in the following block:

In this syntax, we have to define the name and column of that table on which we want to perform the BIN function.

Examples of BIN function

Example 1: This example returns the binary representation of the specified number:

Output:

Binary_of_101
1100101

Example 2: This example returns the binary representation of the specified number:

Output:

Binary_of_2
10

Example 3: This example returns the binary representation of 8:

Output:

Binary_of_8
1000

Example 4: This example returns the binary representation of 255:

Output:

Binary_of_255
11111111

Example 5: This example returns the binary representation of NULL:

SELECT BIN(NULL) AS Binary_of_NULL;

You may also like