I have a number, for example 7
2^0+2^1+2^2=7.
There is a routine that gives the 0,1,2?
If i have 6 i must take 1,2.
With one number i can have many.
maybe ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
set<int>codes;
std::set<int>::iterator it;
int rest=code;
while(rest!=0)
{
for(int i=0; i<100; i++)
{
int x=(int)pow(2,i);
if(x>=rest)
{
rest=rest-(int)pow(2,i-1);
codes.insert(i-1);
}
}
}
|
Last edited on
Use binary, 7 = 0000 0111
( pos -> 7654 3210 <- )
We have 0,1,2 for 7
etc...