Welcome to WebmasterWorld Guest from 100.25.214.89

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)

Junior Member

10+ Year Member

joined:Dec 29, 2005
posts:73
votes: 0


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)

Administrator

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

joined:July 31, 2003
posts:12548
votes: 2


Can you query the data using the bit functions [dev.mysql.com]?
1:11 am on Dec 21, 2009 (gmt 0)

Senior Member from NZ 

WebmasterWorld Senior Member 10+ Year Member

joined:June 9, 2002
posts:861
votes: 0


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.

[webmasterworld.com...]

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

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

Senior Member from NZ 

WebmasterWorld Senior Member 10+ Year Member

joined:June 9, 2002
posts:861
votes: 0


Bingo.

[phpbuilder.com...]

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

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members