fork download
  1. /**/
  2. #include <iostream>
  3. #include <vector>
  4. #include <random>
  5. #include <limits>
  6. #include <random>
  7.  
  8. typedef std::vector < std::uint8_t > DType;
  9.  
  10. DType MakeVector(std::size_t N,unsigned int S=0) {
  11. std::minstd_rand mr(S);
  12. DType R;
  13. std::uniform_int_distribution<> UI(0, std::numeric_limits<std::uint8_t>::max());
  14. for (std::size_t i = 0; i < N; i++) {
  15. R.push_back(UI(mr));
  16. }
  17.  
  18. return R;
  19. }
  20.  
  21. template<class T>
  22. bool ShowBitLH(const T& N) {
  23. for (std::size_t i = 0; i < std::numeric_limits<T>::digits; i++) {
  24. std::cout << ((N & (1 << i)) > 0 ? 1 : 0);
  25. }
  26.  
  27. return true;
  28. }
  29. template<class T>
  30. bool ShowBitHL(const T& N) {
  31. for (std::int64_t i = std::numeric_limits<T>::digits-1; i >=0 ; i--) {
  32. std::cout << (((N & (1ll << i)) > 0) ? 1 : 0);
  33. }
  34.  
  35. return true;
  36. }
  37.  
  38. int main() {
  39. {
  40. //std::uint8_t N = 127;
  41.  
  42. //ShowBitHL(N);
  43. }
  44. DType R = MakeVector(16);
  45.  
  46. for (auto& o : R) {
  47. std::cout << '[' << (int)o << ':';
  48. ShowBitHL(o);
  49. std::cout << ']'<<' ';
  50. }
  51. std::cout << ' ' << std::endl;
  52. return 0;
  53. }
  54.  
  55. /**/
  56.  
  57. /** /
  58. #include <iostream>
  59. #include <vector>
  60. #include <random>
  61. #include <limits>
  62. #include <random>
  63. #include <cstddef>
  64.  
  65. //c++17
  66.  
  67. typedef std::vector < std::byte > DType;
  68.  
  69. DType MakeVector(std::size_t N,unsigned int S=0) {
  70. std::minstd_rand mr(S);
  71. DType R;
  72. std::uniform_int_distribution<> UI(0, std::numeric_limits<std::uint8_t>::max());
  73. for (std::size_t i = 0; i < N; i++) {
  74. R.push_back(std::byte(UI(mr)));
  75. }
  76.  
  77. return R;
  78. }
  79.  
  80. template<class T>
  81. bool ShowBitLH(const T& N) {
  82. for (std::size_t i = 0; i < std::numeric_limits<T>::digits; i++) {
  83. std::cout << ((N & (1 << i)) > 0 ? 1 : 0);
  84. }
  85.  
  86. return true;
  87. }
  88. template<class T>
  89. bool ShowBitHL(const T& N) {
  90. for (std::int64_t i = std::numeric_limits<T>::digits-1; i >=0 ; i--) {
  91. std::cout << (((N & (1ll << i)) > 0) ? 1 : 0);
  92. }
  93.  
  94. return true;
  95. }
  96.  
  97. int main() {
  98. {
  99. //std::uint8_t N = 127;
  100.  
  101. //ShowBitHL(N);
  102. }
  103. DType R = MakeVector(16);
  104.  
  105. for (auto& o : R) {
  106. std::cout << '[' << std::to_integer<std::uint16_t>(o) << ':';
  107. ShowBitHL(std::to_integer<std::uint8_t>(o));
  108. std::cout << ']'<<' ';
  109. }
  110. std::cout << ' ' << std::endl;
  111. return 0;
  112. }
  113.  
  114. /**/
Success #stdin #stdout 0s 4472KB
stdin
Standard input is empty
stdout
[0:00000000] [21:00010101] [153:10011001] [228:11100100] [247:11110111] [48:00110000] [131:10000011] [101:01100101] [67:01000011] [190:10111110] [22:00010110] [143:10001111] [149:10010101] [207:11001111] [151:10010111] [130:10000010]