#include <iostream>
#include <regex>
#include <numeric>
uint64_t stomac( const std::string &mac )
{
static const std::regex r{ "([\\da-fA-F]{2})(:|$)" };
auto it = std::sregex_iterator( mac.begin(), mac.end(), r );
static const auto end = std::sregex_iterator();
return std::accumulate( it, end, 0, []( uint64_t i, const std::sregex_iterator::value_type &v ) {
return ( i << 8 ) + std::stol( v.str(1), nullptr, 16 );
} );
}
int main()
{
std::cout << std::hex << stomac( "00:00:12:24:36:4f" ) << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8cmVnZXg+CiNpbmNsdWRlIDxudW1lcmljPgoKdWludDY0X3Qgc3RvbWFjKCBjb25zdCBzdGQ6OnN0cmluZyAmbWFjICkKewogICAgc3RhdGljIGNvbnN0IHN0ZDo6cmVnZXggcnsgIihbXFxkYS1mQS1GXXsyfSkoOnwkKSIgfTsKCiAgICBhdXRvIGl0ID0gc3RkOjpzcmVnZXhfaXRlcmF0b3IoIG1hYy5iZWdpbigpLCBtYWMuZW5kKCksIHIgKTsKICAgIHN0YXRpYyBjb25zdCBhdXRvIGVuZCA9IHN0ZDo6c3JlZ2V4X2l0ZXJhdG9yKCk7CgogICAgcmV0dXJuIHN0ZDo6YWNjdW11bGF0ZSggaXQsIGVuZCwgMCwgW10oIHVpbnQ2NF90IGksIGNvbnN0IHN0ZDo6c3JlZ2V4X2l0ZXJhdG9yOjp2YWx1ZV90eXBlICZ2ICkgewogICAgICAgICAgICByZXR1cm4gKCBpIDw8IDggKSArIHN0ZDo6c3RvbCggdi5zdHIoMSksIG51bGxwdHIsIDE2ICk7CiAgICB9ICk7Cn0KCmludCBtYWluKCkKewogICAgc3RkOjpjb3V0IDw8IHN0ZDo6aGV4IDw8IHN0b21hYyggIjAwOjAwOjEyOjI0OjM2OjRmIiApIDw8IHN0ZDo6ZW5kbDsKfQo=