There is defiantly more than one way to skin a cat.

Jason
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Friday, May 12, 2000 12:59 PM
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/

Reply via email to