Binary literals can be written in one of the following formats: b'value'
, B'value'
or 0bvalue
, where value
is a string composed by 0
and 1
digits.
Binary literals are interpreted as binary strings, and is convenient to represent VARBINARY, BINARY or BIT values.
To convert a binary literal into an integer, just add 0.
Printing the value as a binary string:
SELECT 0b1000001;
+-----------+
| 0b1000001 |
+-----------+
| A |
+-----------+
Converting the same value into a number:
SELECT 0b1000001+0;
+-------------+
| 0b1000001+0 |
+-------------+
| 65 |
+-------------+