Home  >  Article  >  Database  >  How do we assign a bit value as a number to a user variable?

How do we assign a bit value as a number to a user variable?

WBOY
WBOYforward
2023-08-28 20:05:02860browse

How do we assign a bit value as a number to a user variable?

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:

Using the CAST() function

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)

By adding 0(0)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete