I will try to understand it and see how it works.
How the conversion algorithm works:
Lets convert 0x89. This is 2^7 + 2^3 + 2^0, i.e. 1*2*2*2*2*2*2*2 + 1*2*2*2 + 1. Lets split the multiplies into multiple steps, and tack on the following terms at the appropriate stage:
1 = 1
1*2 = 2
1*2*2 = 4
1*2*2*2 = 8
1*2*2*2*2 + 1 = 16 + 1 = 17
1*2*2*2*2*2 + 1*2 = 32 + 2 = 34
1*2*2*2*2*2*2 + 1*2*2 = 64 + 4 = 68
1*2*2*2*2*2*2*2 + 1*2*2*2 + 1 = 128 + 8 + 1 = 137
Combining the multiplies:
(1*2*2*2*2 + 1)*2*2*2 + 1 = 137
The algorithm works to convert between any two bases. The multiplies and adds are done in the target base (base 10 here, hence bcd), and the multiply value is the source base (2 in this instance.)
Here's the same algorithm converting from base 10 to base 2:
binary = 0;
while ((digit = *string++) != 0)
binary = binary * 10 + (digit - '0');
This is quite simple and familiar looking, right?
I assume everyone else has long since gotten bored...