Let's see if I understood, you have a sequence that is basically "binary" (power of 2) values, ex:
32---16---8----4----2-----1
0----0----0----1----1-----0 is 6
So you can go ahead and convert your input number (which is an int) to binary and then go bit by bit checking if they are turned on.
So lets say you have the number 35, to binary:
32---16---8----4----2-----1
1----0----0----0----1-----1
I will go bit by bit now
- Bit index 1 is turned on, so I have 1!
- Bit index 2 is turned on, so I have 2!
- Bit index 3 is turned off, skip!
- Bit index 4 is turned off, skip!
- Bit index 5 is turned off, skip!
- Bit index 6 is turned on, I have 32!
Result: 1 + 2 + 32 = 35
Hope this helps! :)