We know that the default type for assigning bit values to user variables is a binary string, but we can also assign bit values to numbers in the following two methods:
By using CAST(... AS UNSIGNED), you can assign a place value to a number. The following example will illustrate:
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)
A bit value can be assigned a number by adding 0(0) to it. The following example will illustrate this −
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)
The above is the detailed content of How do we assign a bit value as a number to a user variable?. For more information, please follow other related articles on the PHP Chinese website!