Confused with BITWISE, I'm using MySQL
I think I need to use Bitwise with MySQL.
However, I'm confused with
SELECT 29 | 15;
returns
31
开发者_JAVA技巧
http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html
I have been reading what I can understand about bitwise but I'm lost.
Well, in 29, the bits 16, 8, 4, and 1 are set.
In 15, the bits 8, 4, 2, and 1 are set.
"x Or y" (|) means: "set all bits that are set in x or y or both".
So, in 29 | 15, bits 16, 8, 4, 2, and 1 are all set.
16 + 8 + 4 + 2 + 1 = 31.
Does this answer your question?
It's same as (if you do binary operation)
11101 OR 01111 = 11111 = 31 in decimal
where 11101
is binary representation of decimal 29
and 01111
is binary representation of decimal 15
suggested reads
- The Binary System http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/97F/Readings/student-binary.html
- Bitwise Operators http://www.eskimo.com/~scs/cclass/int/sx4ab.html
精彩评论