Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Determining combination of powers of 2



5:50 am on Dec 18, 2009 (gmt 0)

5+ Year Member

Hey all.

I've been stuck with a particularly tricksy problem. The developer that previously worked on the project I am busy with developed a news module with articles and categories. Each news article can be assigned to one or more news categories.

However, the manner in which these news categories have been referenced is perplexing. The system uses bitwise operations to calculate "new" category IDs (For example, news article with category ID 256 actually belongs to category with ID 8).

The real problem comes in when a news article belongs to multiple categories. The shifted values of the two (or more) genres to which the news article belongs are added together, and then stored as a single integer value in the database. My problem comes in when I'm needing to break this single integer value apart into the constituent category IDs, so that I can query the names of the categories to which it belongs.

If anybody could offer some help, or provide some sort of starting help, I'd seriously appreciate it. My brain is feeling absolutely frazzled - I've been having to deal with logs, which I haven't done since high school! :)


11:11 am on Dec 19, 2009 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Can you query the data using the bit functions [dev.mysql.com]?


1:11 am on Dec 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I've wanted to get into this same powers of 2 system for user permissions, but didn't really get anywhere with it when I last looked into.


It would still be a great way to go if I could crack it.


1:17 am on Dec 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Haven't got time to test it right now, but it looks right.


Featured Threads

Hot Threads This Week

Hot Threads This Month