??? 06/04/04 15:45 Read: times |
#71777 - RE: Little Endian Big endian conversion. Responding to: ???'s previous message |
I second Wolfgang's note that endianess is compiler dependent. In my case with my IAR compiler, it's also version dependent!
You will want to check the code generated by whatever conversion method you choose. I've found smaller faster code using the union conversion like Wolfgang's suggestion as compared to shifting/combining like Mahmood suggested (which was how I always used to do it). The only way to know the endianess of a number is to know its source. For instance, I know that the data coming off my CAN bus is little endian, but my compiler uses big endian...so I know before I do any number crunching I've got to swap bytes around. A while back Dan Henry posted a nice header file to handle endianess, see http://www.8052.com/forum/read.phtml?id=46147 Dennis |