I have a hexadecimal MAC address held in a std::string. What would be the best way to turn that MAC address into an integer-type held in a uint64_t?
I’m aware of stringstream, sprintf, atoi, etc. I’ve actually written little conversion functions with the first 2 of those, but they seem more sloppy than I would like.
So, can someone show me a good, clean way to convert
std::string mac = "00:00:12:24:36:4f";
into a uint64_t?
PS: I don’t have boost/TR1 facilities available and can’t install them where the code will actually be used (which is also why I haven’t copy pasted one of my attempts, sorry about that!). So please keep solutions to straight-up C/C++ calls. If you have an interesting solution with a UNIX system call I’d be interested too!
1 Answer