John Machin wrote: > [EMAIL PROTECTED] wrote: > > >My version assumes three subroutines: extracting > > nibbles, shifting, and adding, Those are pretty simple, so I asked > > if he needed them rather than presenting them. > > Assuming we have > > them, the algorithm is three lines long. > > Perhaps you could enlighten us by publishing (a) the spec for each of > the get_nibble(s), shift, and add subroutines (b) the three-line > algorithm (c) what the algorithm is intended to achieve ...
"For each nibble n of x" means to take each 4 bit piece of the BCD integer as a value from zero to sixteen (though only 0 through 9 will appear), from most significant to least significant. "Adding" integers and "shifting" binary integers is well-defined terminology. I already posted the three-line algorithm. It appeared immediately under the phrase "To turn BCD x to binary integer y," and that is what it is intended to achieve. > > He took a while to state the problem, but was clear from the start > > that he had lists of digits rather than an integer datatype. > > Yes, input was a list [prototyping a byte array] of decimal digits. The > OUTPUT was also a list of something. A few messages later, it became > clear that the output desired was a list of hexadecimal digits. Until > he revealed that the input was up to 24 decimal digits, I was pursuing > the notion that a solution involving converting decimal to binary (in a > 32-bit long) then to hexadecimal was the way to go. > > What is apparently needed is an algorithm for converting a "large" > number from a representation of one base-10 digit per storage unit to > one of a base-16 digit per storage unit, when the size of the number > exceeds the size (8, 16, 32, etc bits) of the "registers" available. I read his "Yes I realized that after writing it." response to Dennis Lee Bieber to mean Bieber was correct and what he wanted was to go from BCD to a normal binary integer, which is base 256. The point of posting the simple high-level version of the algorithm was to show a general form that works regardless of particular languages, register sizes and storage considerations. Those matters can effect the details of how one shifts a binary integer left one bit, but shifting is not complicated in any plausible case. > Is that what you have? I'm sorry my post so confused, and possibly offended you. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list