1

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?

  • can you explain better? I don't get your problem – jcho360 May 17 '12 at 14:52
2

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

For example:

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

MySQL docs are here.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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