Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include<cstdlib>
  2. #include<cstdint>
  3. #include<iostream>
  4. #include<bitset>
  5.  
  6. int main()
  7. {
  8.     const uint32_t n=5;
  9.     for(uint32_t x=0,k=0; k<n; k++)
  10.         for(uint32_t v = (x|=(1u<<k)); v<(1u<<n); )
  11.         {
  12.             std::cout << std::bitset<n>(v) << "\n";
  13.            
  14.             uint32_t t = (v | (v - 1)) + 1;  
  15.             v = t | ((((t & -t) / (v & -v)) >> 1) - 1);
  16.         }
  17.    
  18.     return EXIT_SUCCESS;
  19. }
  20.  
  21.  
  22. ##### Output
  23.  
  24. 00001
  25. 00010
  26. 00100
  27. 01000
  28. 10000
  29. 00011
  30. 00101
  31. 00110
  32. 01001
  33. 01010
  34. 01100
  35. 10001
  36. 10010
  37. 10100
  38. 11000
  39. 00111
  40. 01011
  41. 01101
  42. 01110
  43. 10011
  44. 10101
  45. 10110
  46. 11001
  47. 11010
  48. 11100
  49. 01111
  50. 10111
  51. 11011
  52. 11101
  53. 11110
  54. 11111
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement