In my project i wrote such function for conversion:
// len should be > 0
uint32_t stringToInt(unsigned char const* buffer, int len) {
uint32_t result = buffer[0] - '0';
for (int i = 1; i < len; i++) {
result *= 10;
result += buffer[i] - '0';
}
return result;
}
Are there any stl / boost methods that can do the same with the same speed? If not so then probaly you can further improve my version?
I can not use atoi
because it doesn't allow to provide len
. I also don't want to create temp buffer just for atoi
call.