BCD List to HEX List

bryanjugglercryptographer at yahoo.com bryanjugglercryptographer at yahoo.com
Tue Aug 1 11:31:02 EDT 2006


John Machin wrote:
> bryanjugglercryptographer at yahoo.com wrote:
> > John Machin wrote:
> > > bryanjugglercryptographer at yahoo.com wrote:
> > > > To turn BCD x to binary integer y,
> > > >
> > > >   set y to zero
> > > >   for each nibble n of x:
> > > >     y = (((y shifted left 2) + y) shifted left 1) + n
> > >
> > > Yeah yeah yeah
> > > i.e. y = y * 10 + n
> > > he's been shown that already.
> > >
> > > Problem is that the OP needs an 8-decimal-digit (32-bits) answer, but
> > > steadfastly maintains that he doesn't "have access to" long (32-bit)
> > > arithmetic in his C compiler!!!
> >
> > And he doesn't need one. He might need the algorithms for shift and
> > add.
>
> I hate to impose this enormous burden on you but you may wish to read
> the whole thread. He was given those "algorithms".

Quite some longwinded code and arguing about platforms in the rest
of the thread. 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. Don't know why people
have to make such a big deal of a BCD converter.

> He then upped the
> ante to 24 decimal digits and moved the goalposts to some chip running
> a cut-down version of Java ...

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.


-- 
--Bryan




More information about the Python-list mailing list