
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to convert string to bitset in MySQL?
To convert string to bitset, use the CONV() method. Let us first create a table −
mysql> create table DemoTable ( stringValue BIT(4) ); Query OK, 0 rows affected (3.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(CONV('1110', 2, 10) * 1); Query OK, 1 row affected (0.62 sec) mysql> insert into DemoTable values(b'1011'); Query OK, 1 row affected (0.14 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
Following is the output that displays blank result because the type is bitset −
Following is the query to convert string to bitset and display the result −
mysql> select stringValue+0 AS DECIMAL_VALUE,BIN(stringValue) AS BINARY_VALUE from DemoTable;
This will produce the following output −
+---------------+--------------+ | DECIMAL_VALUE | BINARY_VALUE | +---------------+--------------+ | 14 | 1110 | | 11 | 1011 | +---------------+--------------+ 2 rows in set (0.04 sec)
- Related Articles
- How to convert string to time in MySQL?
- How to convert a string to date in MySQL?
- How to convert string to 24-hour datetime format in MySQL?
- Convert hex string to number in MySQL?
- Convert string (varchar) to double in MySQL
- Convert string (varchar) to timestamp format in MySQL?
- How to Convert Hashtable to String?
- How to convert Boolean to String in JavaScript?
- How to convert Number to String in JavaScript?
- How to convert String to Number in JavaScript?
- How to convert String to Boolean in JavaScript?
- How to convert ObjectId to string in MongoDB
- How to convert string to binary in Python?
- How to convert int to String in java?
- How to convert String to Date in java?

Advertisements