fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. typedef std::vector<bool> vb;
  5.  
  6. int base10(const vb &value)
  7. {
  8. int result = 0;
  9. int bit = 1;
  10.  
  11. for (vb::const_reverse_iterator b = value.rbegin(), e = value.rend(); b != e; ++b, bit <<= 1)
  12. result += (*b ? bit : 0);
  13.  
  14. return result;
  15. }
  16.  
  17. int main()
  18. {
  19. vb value1({1, 0, 1}); // 5
  20. vb value2({1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1}); // 5
  21.  
  22. std::cout << base10(value1) << '\n' << base10(value2);
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
5
32261