Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdlib>
- #include<cstdint>
- #include<iostream>
- #include<bitset>
- int main()
- {
- const uint32_t n=5;
- for(uint32_t x=0,k=0; k<n; k++)
- for(uint32_t v = (x|=(1u<<k)); v<(1u<<n); )
- {
- std::cout << std::bitset<n>(v) << "\n";
- uint32_t t = (v | (v - 1)) + 1;
- v = t | ((((t & -t) / (v & -v)) >> 1) - 1);
- }
- return EXIT_SUCCESS;
- }
- ##### Output
- 00001
- 00010
- 00100
- 01000
- 10000
- 00011
- 00101
- 00110
- 01001
- 01010
- 01100
- 10001
- 10010
- 10100
- 11000
- 00111
- 01011
- 01101
- 01110
- 10011
- 10101
- 10110
- 11001
- 11010
- 11100
- 01111
- 10111
- 11011
- 11101
- 11110
- 11111
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement