Bug #10578 Bin function does not work correctly on variables having binary value.
Submitted: 12 May 2005 9:42 Modified: 13 May 2005 8:30
Reporter: Disha Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.5 Beta OS:Windows (Windows 2000 Server)
Assigned to: CPU Architecture:Any

[12 May 2005 9:42] Disha
Description:
If a variable that contains a binary value is passed to the BIN function then incorrect result is displayed.

How to repeat:
1. Start the MySQL client and connect to the database with valid user and password.
2. Set the delimiter to //
3. Set a variable to a bit value as follows:
   set @a=b'11110000'//
4. Now execute the following command:
   select bin(@a+0)//

Expected Results: 
1. The output of BIN function should be correct that is '11110000'.

Actual Results: 
1. The output of the BIN function is 0.
2. If we pass a binary value to the function then correct result is retrieved. The following is the example for the same
   mysql> select bin(b'11110000'+0)//
   +--------------------+
   | bin(b'11110000'+0) |
   +--------------------+
   | 11110000           |
   +--------------------+
   1 row in set (0.00 sec)
   mysql>
[12 May 2005 9:55] MySQL Verification Team
Verified on Linux BK source.
[13 May 2005 8:30] Sergei Golubchik
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

b'...' specifies a *string*.

mysql> set @a=b'11110000';
Query OK, 0 rows affected (0.02 sec)

mysql> select @a;
+------+
| @a   |
+------+
| П    |
+------+
1 row in set (0.02 sec)

mysql> select hex(@a);
+---------+
| hex(@a) |
+---------+
| F0      |
+---------+
1 row in set (0.00 sec)

mysql> select bin(ascii(@a));
+----------------+
| bin(ascii(@a)) |
+----------------+
| 11110000       |
+----------------+
1 row in set (0.02 sec)