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?
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 only takes a minute to sign up.
Sign up to join this communityI 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?
Use logical shifts <<
plus a bitwise or |
operation.
For example:
SELECT (col1<<16) | (col2<<15) | (col3<<14) | (col4<<13) ...
MySQL docs are here.