The following was given as an example of how to convert a binary string to an int.
I have no trouble going through it step by step and seeing that it does indeed work, but I'm having trouble understanding why it works and what the principle behind it is. Can anyone explain?Code:int bstr_to_dec(const char * str) { int val = 0; while (*str != '\0') val = 2 * val + (*str++ - '0'); return val; }