[RESOLVED] Logic With days
Hi All,
We have a system were a user chooses a combination of days from a calander. We then insert a values in the databse based on the following
Sunday - 1
Monday - 2
Tuesday - 4
Wednesday - 8
Thursday - 16
Friday - 32
Saturday - 64
So if they picked Monday and Friday we would insert 34, or if they picked Monday,Tuesday and Thursday we would insert 22.
Now my question is how do I reverse this easily in code, to find out what days they have picked. So I get fed 22 from the database how do I figure out what combination of days make up that value.
Sorry it sounds a bit like a homework project bit it really isn't.
The only thing I can think of is creating the mother of all case statements but I know there must be a better way.