Reverse binary logic with numbers

I'm making a project where i'm using a PS1 controller with the Psx library.
All works nice i receive values.
But i don't know how to use thoses values...
Each button send a value of a 2^n, so when you push more then one button you get a unique value which can only be obtained by a single combination of buttons.
I was wondering how can i know the combination with maths.
Thanks

Code:

---



```
uint8_t value = 0b00010101;    // The value received from the controller
const uint8_t n = 8;          // Number of buttons (<= [nobbc]8)[/nobbc]
const uint8_t end = 1 << n;    // The stop mask
for (
uint8_t mask = 1, ctr = 1;
mask != end;
mask <<= 1, ++ctr
) {
if (value & mask) {
Serial.print("Button ");
Serial.printcolor=#000000[/color];
Serial.println(" is active");
}
}
```

This will print

Button 1 is active
Button 3 is active
Button 5 is active

Pieter