Bitmasking Subset Generation of Subset

Правка en2, от sar0603, 2020-11-19 14:42:44
//S = bitmask representation of available subset
//{1,2,3} ,S = 3 means only {2,3} are available since binary(3) = 0 1 1
for (int G = S; G != 0 ; G = (G - 1) & S)

This one liner generates subset of a subset in bit representation form. Would be grateful if anyone can give any intuition or explain the above line. Dont want to mug this up.

Eg: ~~~~~ The subset = 1110 The subsets of subset : 1110 1100 1010 1000 0110 0100 0010 ~~~~~

Теги #bitmask, #combination, #combinatorics, #subset

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский sar0603 2020-11-19 14:42:44 113
en1 Английский sar0603 2020-11-19 14:33:33 414 Initial revision (published)