Get days on basis of Sum of values of Lets suppose i have list of days :


*

*Sun - 1 

*Mon - 2 

*Tue - 4

*Wed - 8

*Thu - 16 

*Fri - 32 

*Sat - 64


Now user can select one or more then one from checklist .My database just storing the sum of days (Example: if user selected sun and mon then value is getting stored in database is 3)
.now i want to show user days he selected. What will be the formula to compute this.

Hint: Write the sum of days in binary.
Any integer $n$ from $0$ to $127$ can be uniquely written as $$n=a_0\cdot 1 + a_1\cdot 2 + a_2\cdot 4 + a_3\cdot 8 + a_5\cdot 16 + a_6\cdot 32 + a_7\cdot 64$$
where $a_i\in\{0,1\}$. In binary, $n$ is then written as $$n=a_7a_6a_5a_4a_3a_2a_1a_0.$$
Simply looking at the digits of the binary expression of $n$ then gives you the days that were selected.
