![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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