Home > Database > Mysql Tutorial > 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
Release: 2023-08-28 20:05:02
forward
904 people have browsed it

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template