Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How can we assign a bit value as a number to a user variable?
As we know that the default type of a bit values assigned to user variables is binary strings but we can also assign a bit value to a number by using the following two methods −
By using CAST() function
With the help of CAST(… AS UNSIGNED) the bit value can be assigned a number. The following example will illustrate it −
mysql> SET @abc = CAST(0b1000011 AS UNSIGNED); Query OK, 0 rows affected (0.00 sec) mysql> Select @abc; +------+ | @abc | +------+ | 67 | +------+ 1 row in set (0.00 sec)
By adding 0(+0)
The bit value can be assigned a number by adding 0(+0) to the bit value. The following example will illustrate it −
mysql> SET @abc = 0b1000011+0; Query OK, 0 rows affected (0.00 sec) mysql> Select @abc; +------+ | @abc | +------+ | 67 | +------+ 1 row in set (0.00 sec)
Advertisements
