Not a quick fix perhaps, but remember what a number base does for digits. In base 10 (the normal base), this:
Originally Posted by Chris87
10101, means that, from right to left, we have 1 one, 0 * base (10), 1 * base * base (10^2nd), 0 * base * base * base (10^3rd), and 1 * base * base * base * base. (10^4th)
Adding it all up then we get:
You see the obvious pattern here. It works the very same way for binary (base 2) numbers: 1 == 1, 10 == 1 * base (2), 100 == 1 * base * base (1 * 2^2nd), etc.
So knowing the above, and using the mod (remainder) math operator in C "%", writing up such function becomes a simple loop (either a while, or a for loop will work splendidly).
Now, let's see you come up with a try in code. You'll learn a lot more by doing it, than by merely seeing how someone else does it, for sure.