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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/04/04 13:25
Read: times


 
#71750 - RE: Little Endian Big endian conversion.
Responding to: ???'s previous message
The byte order for 8052 processors depends on the used compiler. Keil use Big endian while SDCC use Little endian p.e.
All intel based PC with x86 processors I know use little endian byte order.
If you develop do byte order switching on the PC driver side. Discribe that your device use a specific byte order nevertheless to witch host is is connected.
Also the tcp/ip protokoll always use big endian.

A sample how to detect and convert

/* swap bytes to little-endian if host cpu isn't it */
static unsigned short _swap16(unsigned short var)
{
union test {
unsigned short r;
unsigned char b[2];
} t;
unsigned char c1;/* swap bytes to little-endian if host cpu isn't it */
static unsigned short _swap16(unsigned short var)
{
union test {
unsigned short r;
unsigned char b[2];
} t;
unsigned char c1;
t.r=0x55AA;
if (t.b[0]==0xAA) /* little endian machine */
return var;
t.r = var;
c1=t.b[0];
t.b[0]=t.b[1];
t.b[1] = c1;
return t.r;
}

BTW a similar algorthmus is included in all UNIX systems with will run on 32-bit processors with different byte orders to make the code machine independent.

List of 23 messages in thread
TopicAuthorDate
Little Endian Big endian conversion.            01/01/70 00:00      
   RE: Little Endian Big endian conversion.            01/01/70 00:00      
      RE: Little Endian Big endian conversion.            01/01/70 00:00      
         RE: Little Endian Big endian conversion.            01/01/70 00:00      
            RE: Little Endian Big endian conversion.            01/01/70 00:00      
               RE: Little Endian Big endian conversion.            01/01/70 00:00      
                  RE: Little Endian Big endian conversion.            01/01/70 00:00      
                     RE: Little Endian Big endian conversion.            01/01/70 00:00      
               RE: Little Endian Big endian conversion.            01/01/70 00:00      
               Totally & Utterly Impossible!            01/01/70 00:00      
         RE: Little Endian or Big endian?            01/01/70 00:00      
      RE: Little Endian Big endian conversion.            01/01/70 00:00      
         RE: Junk            01/01/70 00:00      
   RE: Little Endian Big endian conversion.            01/01/70 00:00      
   RE: Little Endian Big endian conversion.            01/01/70 00:00      
      RE: machine-independent            01/01/70 00:00      
      RE: Little Endian Big endian conversion.            01/01/70 00:00      
         RE: Compiler-dependence            01/01/70 00:00      
            RE: Compiler-dependence            01/01/70 00:00      
   RE: Little Endian Big endian conversion.            01/01/70 00:00      
      RE: Little Endian Big endian conversion.            01/01/70 00:00      
   A Useful Link            01/01/70 00:00      
   RE: Little Endian Big endian conversion.            01/01/70 00:00      

Back to Subject List