Usually a lookup table is by far the fastest algorithm.  But, on the 68K a
loop of shifts and ors might be as fast.  It might be interesting to compare
the code that CW generates for your function with the one below.

-jjf

Byte SwapByte(Byte oldbyte)
{
   int i;
   Byte newbyte = 0;

   for (i=0; i<8 ; i++)
   {
      newbyte <<= 1;
      newbyte |= (oldbyte & 1);
      oldbyte >>= 1;
   }

   return newbyte;
}

-----Original Message-----
From: Robert Herold [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 12, 2000 1:10 PM
To: Palm Developer Forum
Subject: RE: Byte order


Or how about this:

Byte swap_byte(Byte b)
{
    static Byte swapped_nibble[16] = { 
        0x00, 0x80, 0x40, 0xC0, 
        0x20, 0xA0, 0x60, 0xe0,
        0x10, 0x90, 0x50, 0xd0,
        0x30, 0xb0, 0x70, 0xf0
    };

    return swapped_nibble[b & 0x0f] + (swapped_nibble[(b & 0xf0) >> 4] >>
4);
}

-- bob


====================
Robert Herold           (650) 627-3302
Webvan Group, Inc       (650) 627-3948 (fax)
310 Lakeside Drive      [EMAIL PROTECTED]
Foster City, CA  94404  www.webvan.com


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 12, 2000 12:00 PM
To: Palm Developer Forum
Subject: Re: Byte order


This function seems like its doing a lot of work, what about something like 
this instead:

Byte swap_byte(Byte byOld)
{
    Byte    byNew = 0;

    if (byOld & 0x01) { byNew |= 0x80; }
    if (byOld & 0x02) { byNew |= 0x40; }
    if (byOld & 0x04) { byNew |= 0x20; }
    if (byOld & 0x08) { byNew |= 0x10; }
    if (byOld & 0x10) { byNew |= 0x08; }
    if (byOld & 0x20) { byNew |= 0x04; }
    if (byOld & 0x40) { byNew |= 0x02; }
    if (byOld & 0x80) { byNew |= 0x01; }

    return byNew;
}

In a message dated 5/12/00 12:32:49 PM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:

<< Byte swap_byte(Byte old_byte){
 
   Byte new_byte;
   Byte working_byte[8];
   int  i;
 
 
   new_byte=0x00; // zero out new_byte
 
   for(i=0;i<8;i++)
     working_byte[i]=0x00;  // zero out working bytes
 
   working_byte[0]=(old_byte << 7); // bit 1
 
   working_byte[1]=(old_byte >> 1); // bit 2
   working_byte[1]=(working_byte[1] << 7);
   working_byte[1]=(working_byte[1] >> 1);
 
   working_byte[2]=(old_byte >> 2); // bit 3
   working_byte[2]=(working_byte[2] << 7);
   working_byte[2]=(working_byte[2] >> 2);
 
   working_byte[3]=(old_byte >> 3); // bit 4
   working_byte[3]=(working_byte[3] << 7);
   working_byte[3]=(working_byte[3] >> 3);
 
   working_byte[4]=(old_byte >> 4); // bit 5
   working_byte[4]=(working_byte[4] << 7);
   working_byte[4]=(working_byte[4] >> 4);
 
   working_byte[5]=(old_byte >> 5); // bit 6
   working_byte[5]=(working_byte[5] << 7);
   working_byte[5]=(working_byte[5] >> 5);
 
   working_byte[6]=(old_byte >> 6); // bit 7
   working_byte[6]=(working_byte[6] << 7);
   working_byte[6]=(working_byte[6] >> 6);
 
   working_byte[7]=(old_byte >> 7); // bit 8
 
 
 
   for(i=0;i<8;i++){
 
      new_byte=(new_byte | working_byte[i]);
 
   }  // end for loop
 
   return(new_byte);
 
 } // end function >>

-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to