Skip to content

Latest commit

 

History

History
40 lines (33 loc) · 553 Bytes

printing_all_submask.md

File metadata and controls

40 lines (33 loc) · 553 Bytes

visualization

take 25 for example, binary form 11001
consider it as photoshoped image composed of various layer over 00000
time to sepearate them out then.

- 11001
- 11000
- 10001
- 10000
- 01001
- 01000
- 00001
void printBinary(int n) {
  for (int i = 10; i >= 0; i--) {
    printf("%d", ((n >> i) & 1));
  }
  printf("\n");
}

void SubMasks(int n) {
  for (int s = n; s; s = (s - 1) & n) {
  cout << s << ": ";
    printBinary(s);
  }
}

int main() {
  int n = 25;
  cin >> n;
  SubMasks(n);

  return 0;
}