Possible Duplicate:
Converting string of 1s and 0s into binary value
Lets say that I have string which contains 1024 characters (represents 0 and 1). I want to present it as an number in decimal base (also as a string). The tricky part is that i have to do it in C/C++ without 3rd part libraries. Any clues?
There are probably more efficient ways, but I’d have an array of decimal digits, and implement a ‘left-shift’ function on it which runs from the least significant digit, doubling them and carrying over into the next.
It’s then just a job of reading your binary data in one bit at a time and ‘left-shifting’ the decimal array and ‘OR’ing in the binary digit as required.
Just iterate through the decimal digits to print out the answer.
See it running here: http://ideone.com/CibAfw