fork(2) download
  1. #include <iostream>
  2. #include <regex>
  3. #include <numeric>
  4.  
  5. uint64_t stomac( const std::string &mac )
  6. {
  7. static const std::regex r{ "([\\da-fA-F]{2})(:|$)" };
  8.  
  9. auto it = std::sregex_iterator( mac.begin(), mac.end(), r );
  10. static const auto end = std::sregex_iterator();
  11.  
  12. return std::accumulate( it, end, 0, []( uint64_t i, const std::sregex_iterator::value_type &v ) {
  13. return ( i << 8 ) + std::stol( v.str(1), nullptr, 16 );
  14. } );
  15. }
  16.  
  17. int main()
  18. {
  19. std::cout << std::hex << stomac( "00:00:12:24:36:4f" ) << std::endl;
  20. }
  21.  
Success #stdin #stdout 0s 15344KB
stdin
Standard input is empty
stdout
1224364f