How to generate all possible combinations of a 24 digit binary number?

StackOverflow https://stackoverflow.com/questions/18904384

  •  29-06-2022
  •  | 
  •  

Pergunta

I basically have a 24 digit number and I need to get every combination of that number with 1's and 0's I know that there is over 16,700,000 possible combinations. I need to get every single possible combination for a minimax algorithm game that I am developing. If you have an algorithm for this that would be awesome. Thanks.

Foi útil?

Solução

You can just iterate an unsigned int from 0 to 2^24-1:

for (uint32_t i = 0; i < 1U<<24; ++i)
{
    // do something with LS 24 bits of i ...
}

This will give you all possible bit patterns in the bottom 24 bits of i.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top