Display MySQL BIT Values in Printable Form



Actually, Bit values are returned as binary values but we can also display them in the printable form with the help of following −

By adding 0

We can display Bit values in printable form by adding 0 to them. Following the example from the bit_testing table can be used to understand it −

mysql> Select bittest+0 from bit_testing;
+-----------+
| bittest+0 |
+-----------+
|       170 |
|         5 |
|         5 |
+-----------+
3 rows in set (0.00 sec)

By using conversion function BIN(),OCT(),HEX()

We can also display Bit values in printable form by using BIN() conversion function. Following the example from the bit_testing table can be used to understand it −

mysql> Select BIN(bittest+0) from bit_testing;
+----------------+
| BIN(bittest+0) |
+----------------+
| 10101010       |
| 101            |
| 101            |
+----------------+
3 rows in set (0.00 sec)

mysql> Select OCT(bittest+0) from bit_testing;
+----------------+
| OCT(bittest+0) |
+----------------+
| 252            |
| 5              |
| 5              |
+----------------+
3 rows in set (0.05 sec)

mysql> Select HEX(bittest+0) from bit_testing;
+----------------+
| HEX(bittest+0) |
+----------------+
| AA             |
| 5              |
| 5              |
+----------------+
3 rows in set (0.00 sec)
Updated on: 2020-06-22T05:39:10+05:30

76 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements