Ok, I have the code done in a way that works great and uses the increment ++ and decrement — operators.
unsigned int atob(const char* input)
{
int i = 0;
while (input[i] == '0' || input[i] == '1') i++;
unsigned result = 0;
unsigned currentBit = --i;
while ((*input == '0') || (*input == '1')) {
char isCurrentBitSet = *input == '1';
unsigned setValue = (isCurrentBitSet << currentBit--);
result |= setValue;
input++;
}
return result;
}
Now, I need to get rid of all dec(–)/inc(++) except for input++ at the bottom of the while statement. I am baffled at how to do this implementation.
Here you go:
Saves some stack space too 🙂