Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a mySQL table with multiple columns (tinyint) with 0 or 1 values

I want to convert all these values into bits in a single integer column So a column named column1 will go to MSB another column will set 2nd bit etc...

How do I do it?

share|improve this question
    
can you explain better? I don't get your problem –  jcho360 May 17 '12 at 14:52
add comment

1 Answer

up vote 2 down vote accepted

Use logical shifts << plus a bitwise or | operation.

For example:

SELECT (col1<<16) | (col2<<15) | (col3<<14) | (col4<<13) ...

MySQL docs are here.

share|improve this answer
    
As long as a user remembers the order of the columns processed and has no need to do any mass querying of a single bit, this look like a good solution. +1 –  RolandoMySQLDBA May 17 '12 at 16:23
    
You mean bitwise OR | operator. Thanks ! that was helpful –  Nir May 17 '12 at 16:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.