Bug #44614 BIT_COUNT returns '1' for all powers-of-two values
Submitted: 1 May 2009 18:48 Modified: 1 May 2009 19:00
Reporter: Justin Swanhart Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: DML Severity:S1 (Critical)
Version:5.0.45,5.1.32 OS:Any
Assigned to: CPU Architecture:Any

[1 May 2009 18:48] Justin Swanhart
Description:
mysql> select i, pow(2,i), bit_count(pow(2,i)) from pow2;
+----+------------+---------------------+
| i  | pow(2,i)   | bit_count(pow(2,i)) |
+----+------------+---------------------+
|  1 |          2 |                   1 |
|  2 |          4 |                   1 |
|  3 |          8 |                   1 |
|  4 |         16 |                   1 |
|  5 |         32 |                   1 |
|  6 |         64 |                   1 |
|  7 |        128 |                   1 |
|  8 |        256 |                   1 |
|  9 |        512 |                   1 |
| 10 |       1024 |                   1 |
| 11 |       2048 |                   1 |
| 12 |       4096 |                   1 |
| 13 |       8192 |                   1 |
| 14 |      16384 |                   1 |
| 15 |      32768 |                   1 |
| 16 |      65536 |                   1 |
| 17 |     131072 |                   1 |
| 18 |     262144 |                   1 |
| 19 |     524288 |                   1 |
| 20 |    1048576 |                   1 |
| 21 |    2097152 |                   1 |
| 22 |    4194304 |                   1 |
| 23 |    8388608 |                   1 |
| 24 |   16777216 |                   1 |
| 25 |   33554432 |                   1 |
| 26 |   67108864 |                   1 |
| 27 |  134217728 |                   1 |
| 28 |  268435456 |                   1 |
| 29 |  536870912 |                   1 |
| 30 | 1073741824 |                   1 |
| 31 | 2147483648 |                   1 |
| 32 | 4294967296 |                   1 |
+----+------------+---------------------+
32 rows in set (0.00 sec)

How to repeat:
CREATE TABLE `pow2` (
  `i` tinyint(4) NOT NULL auto_increment,
  PRIMARY KEY  (`i`)
) ENGINE=MyISAM AUTO_INCREMENT=33 DEFAULT CHARSET=latin1;

INSERT INTO `pow2` VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),(30),(31),(32);

select i, pow(2,i), bit_count(pow(2,i)) from pow2;
[1 May 2009 19:00] Justin Swanhart
I'm dumb.  I forgot to subtract one.

all powers of two should return 1...