for(int m = N; m >= 0; m--) {  for(int s = m; s = (s- 1) & m; ) {    // get all submasks.  }}