Intereting Posts

A conceptual understanding of transmutations (and bosonizations) of (braided) Hopf algebras
how to prove the chain rule?
How to prove that this solution of heat equation is not a tempered distribution?
Prove by induction that $a^{4n+1}-a$ is divisible by 30 for any a and $n\ge1$
Confused about complex numbers
If $A$ is compact and $B$ is closed, show $d(A,B)$ is achieved
3d geometry: triangle 2 points known, find 3rd point
Convert this equation into the standard form of an ellipse
A linear operator on a finite dimensional Hilbert space is continuous
Product of reflections is a rotation, by elementary vector methods
Inducing homomorphisms on localizations of rings/modules
Prove a function is one-to-one and onto
On limits, schemes and Spec functor
How to compute the following definite integral
Motivation of the Gaussian Integral

The title is not clear what is my problem. I have one number which is the sum of (total) some numbers and I want to know what numbers are included in that number. I have some permissions (as you see below) and I just get one number and I need to return permissions a user has.

```
1: "Permission One",
2: "permission Two",
4: "permission Three",
8: "permission Four",
16: "permission Five"
```

I just get one number (from the server-side) and I need a function that returns what permissions this user has.

For example, when I get `9`

, it means:

- Determining if an arbitrary point lies inside a triangle defined by three points?
- How to Solve this Boolean Equations?
- Is 'every exponential grows faster than every polynomial?' always true?
- Finding the largest equilateral triangle inside a given triangle
- Median of medians algorithm
- How does Knuth's algorithm for calculating logarithm work?

```
8+1
```

Or when I get `7`

it should return:

```
4+2+1
```

*I am not familiar with math language, please guide me with a step-by-step answer*

**EDIT:**

Here is my current algorithm:

I already wrote a function, but I need to have a better solution.

- The number is
`x`

- I have an array of permissions
*(like*`m=[1, 2, 4, 8, 16, ...]`

) -
Add the first number which is smaller the

`x`

from`m`

array. (if`x`

is 10, then 8 will be added to`permission`

array) -
Try the next smaller value of m

*(In this case, I add*`4+m`

which is bigger that`x`

, then we will try with next smaller number) - If
`x==m`

that is it! Finish and return`x`

array. else, go back to**6** - If
`x==all m children from the current number`

, finish it. else go to**7** - if
`x!=m`

go to**4**

**live demo of my algorithm**

I am looking for a better, faster and also really mathematical solution. Any idea?

Thanks

- injective and surjective
- Any problem computable in $k$ memory slots can be computed with polynomials.
- Describing a Wave
- Show that $f(x) = x$ if $f(f(f(x))) = x$.
- Secret santa problem
- Does this pattern have anything to do with derivatives?
- How do I find out the symmetry of a function?
- If $(f\circ g)(x)=x$ does $(g\circ f)(x)=x$?
- number of derangements
- Counterexample for a non-measurable function?

It can be easily done by bitwise AND, your code snippet was in JavaScript, JavaScript bitwise AND operator symbol is `&`

, and here is how you can do it:

```
function checkRoles(roleToCheck, rolesChecksum){
return roleToCheck == (roleToCheck & rolesChecksum);
}
//For example, rolesChecksum is 10:
checkRoles(1, 10) //Returns false
checkRoles(2, 10) //Returns true
checkRoles(8, 10) //Returns true
```

*Thanks for users who commented under the question and made this answer possible*

- If $G/Z(G)$ is cyclic, then $G$ is abelian
- Eventually periodic point and homeomorphism.
- A mouse leaping along the square tile
- Calculate $ \lim \limits_{x \to 0} \left( \dfrac{\sqrt{1 + 4x} – \sqrt{1 + 6x}}{x^2} \right). $
- Cumulative Distribution Function of Sum two Weibull random variables
- Is calculating the summation of derivatives “mathematically sound”?
- If a relation is symmetric and transitive, will it be reflexive?
- please solve a 2013 th derivative question?
- Is $M=\{(x,y)\in \Bbb{R}^2 : x^2 = y^5\}$ a differentiable submanifold?
- Asymptotics of $1^n + 2^{n-1} + 3^{n-2} +\cdots + (n-1)^2 + n^1$
- Help with logarithmic definite integral: $\int_0^1\frac{1}{x}\ln{(x)}\ln^3{(1-x)}$
- $\mathbb Z^n/\langle (a,…,a) \rangle \cong \mathbb Z^{n-1} \oplus \mathbb Z/\langle a \rangle$
- Funny thing. Multiplying both the sides by 0?
- $f$ such that $\sum a_n$ converges $\implies \sum f(a_n)$ converges
- $2^{50} < 3^{32}$ using elementary number theory