How can we enter numerical values as a BINARY number in MySQL statement?

MySQLMySQLi Database

Following are the two approaches with the help of which we can enter numeric values as a BINARY number −

By prefix ‘B’

In this approach we need to quote binary numbers within single quotes with a prefix of B. Then BINARY number string will be automatically converted into a numerical value based on the expression context.

Example

mysql> Select B'1110'+0;
+-----------+
| B'1110'+0 |
+-----------+
|        14 |
+-----------+
1 row in set (0.00 sec)

By prefix 0b

In this approach, we need to write BINARY numbers without any quotes with a prefix of 0b. Then BINARY number string will be automatically converted into a numerical value based on the expression context.

Example

mysql> Select 0b1110+0;
+----------+
| 0b1110+0 |
+----------+
|       14 |
+----------+
1 row in set (0.00 sec)
raja
Published on 22-Feb-2018 07:48:56
Advertisements