Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/05/06 20:56
Modified:
  01/05/06 21:34

Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#106638 - Still simple, but faster
Responding to: ???'s previous message
Mahmood Elnasser said:
Couldn't think of a simpler approach to do BIN2BCD.

#define DIM(a)  (sizeof(a) / sizeof(a[0]))

unsigned short PowTenTbl[] =
{
    10000,
    1000,
    100,
    10,
    1
};

void BinToBcd(unsigned short bin, unsigned char *bcd)
{
    unsigned short powTen;
    unsigned char  digit;
    unsigned char  i;

    for (i = 0; i != DIM(PowTenTbl); i++)
    {
        digit = 0;
        powTen = PowTenTbl[i];

        while (bin >= powTen)
        {
            bin -= powTen;
            digit++;
        }

        *bcd++ = digit;
    }
}


List of 26 messages in thread
TopicAuthorDate
Weekend Puzle            01/01/70 00:00      
   symmetry            01/01/70 00:00      
      no printf            01/01/70 00:00      
   Dont' know but...            01/01/70 00:00      
      Don't be fast on the trigger please            01/01/70 00:00      
         Ah but..            01/01/70 00:00      
            var            01/01/70 00:00      
   can't answer            01/01/70 00:00      
   oddometer            01/01/70 00:00      
      Well Done !!            01/01/70 00:00      
         simple but slow            01/01/70 00:00      
         Still simple, but faster            01/01/70 00:00      
            No fun at all.            01/01/70 00:00      
               32-bit / 10-digit conversion            01/01/70 00:00      
            timing            01/01/70 00:00      
               Big Display            01/01/70 00:00      
                  if that is not good enough            01/01/70 00:00      
                  Even my old eyes could see that! n/t            01/01/70 00:00      
               ideas            01/01/70 00:00      
            Optimisation and comment            01/01/70 00:00      
               Re: comment            01/01/70 00:00      
   puzzle            01/01/70 00:00      
   Puzzle            01/01/70 00:00      
      ok ok            01/01/70 00:00      
         decimal unpacker            01/01/70 00:00      
   a quick look reveal that it seems to be            01/01/70 00:00      

Back to Subject List