1
SET @var = b'01011010';
SELECT BIN(@var);

Note that 01011010 == 'Z';

Returns:

+-----------+
| BIN(@var) |
+-----------+
| 0         |
+-----------+

MySql manual states:

"Bit values are returned as binary values. To display them in printable form, add 0 or use a conversion function such as BIN(). "

Why does this conversion function not work properly and to actually get 'Z' all you need to do is select @var:

SELECT @var;
+------+
| @var |
+------+
| Z    |
+------+

1 Answer 1

1

Could you try this?

mysql> SELECT BIN(ORD(@var));
+----------------+
| BIN(ORD(@var)) |
+----------------+
| 1011010        |
+----------------+
1 row in set (0.00 sec)

BIN() accepts numeric type. so you need to convert z to 90.

mysql>  SELECT @var, ORD(@var), BIN('Z'), BIN(90);
+------+-----------+----------+---------+
| @var | ORD(@var) | BIN('Z') | BIN(90) |
+------+-----------+----------+---------+
| Z    |        90 | 0        | 1011010 |
+------+-----------+----------+---------+
1 row in set (0.00 sec)
Sign up to request clarification or add additional context in comments.

1 Comment

It could turn out alright but I am trying to understand how they got the values from this section: dev.mysql.com/doc/refman/5.7/en/bit-field-literals.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.