Bug #100223 unexpected returned result of & operation

Submitted: 15 Jul 2020 7:12 Modified: 15 Jul 2020 13:12
Reporter: ick R Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0.21 OS:Any
Assigned to: CPU Architecture:Any

[15 Jul 2020 7:12] ick R
Description:
I'm not sure about the correctness of the results returned by 'select bin(-24656)  & bin(1);' (which is 1) and 'select bin(24656)  & bin(1);' (which is 0).How does '&' work in this process?

How to repeat:
select bin(-2456);
select bin(-24656)  & bin(1);

select bin(2456);
select bin(24656)  & bin(1);
[15 Jul 2020 7:38] ick R
Another case:
select CONV(-2456,10,2) & 1;
--1
select CONV(2456,10,2) & 1;
--0
[15 Jul 2020 8:11] ick R
sorry,it should be :
select bin(-24656);
select bin(-24656)  & bin(1);

select bin(24656);
select bin(24656)  & bin(1);

in HOW TO REPEAT
[15 Jul 2020 13:12] MySQL Verification Team
Hi Mr. R,

Thank you for your bug report.

However, this is not a bug, but a support question.

In short, the operator '&' works as a binary one and not as a logical one.

Also, please read the following comment.
[15 Jul 2020 13:12] MySQL Verification Team
We're sorry, but the bug system is not the appropriate forum for asking help on using MySQL products. Your problem is not the result of a bug.

For details on getting support for MySQL products see http://www.mysql.com/support/
You can also check our forums (free) at http://forums.mysql.com/

Thank you for your interest in MySQL.
[15 Jul 2020 13:25] Yushan ZHANG
I think the bug is related to the `&` result:

select CONV(-2456,10,2);
-- incorrect 5.7.31 & 8.0.21
select CONV(-2456,10,2) & 1;
select (-2456) & 1;

It is a bitwise operation, then the second query should give the same result as the last one, however, it returns 1.
[15 Jul 2020 13:27] Yushan ZHANG
Forgot to append the result to the queries:

-- incorrect
mysql> select CONV(-2456,10,2) & 1;
+----------------------+
| CONV(-2456,10,2) & 1 |
+----------------------+
|                    1 |
+----------------------+
1 row in set (0.00 sec)

mysql> select (-2456) & 1;
+-------------+
| (-2456) & 1 |
+-------------+
|           0 |
+-------------+
1 row in set (0.00 sec)

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.