Jules
Jules

Reputation: 7766

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

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.

Upvotes: 1

Views: 3712

Answers (2)

Nishant
Nishant

Reputation: 55866

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

Upvotes: 1

Spiny Norman
Spiny Norman

Reputation: 8327

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?

Upvotes: 5

Related Questions