Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
261 | giacomo | 1 | #include "endn.h" |
2 | |||
3 | /****************************************************************************** |
||
4 | FUNCTION: SwapEndian |
||
5 | PURPOSE: Swap the byte order of a structure |
||
6 | EXAMPLE: float F=123.456;; SWAP_FLOAT(F); |
||
7 | ******************************************************************************/ |
||
8 | |||
9 | void *SwapEndian(void* Addr, const int Nb) { |
||
10 | static char Swapped[16]; |
||
11 | switch (Nb) { |
||
12 | case 2: Swapped[0]=*((char*)Addr+1); |
||
13 | Swapped[1]=*((char*)Addr ); |
||
14 | break; |
||
15 | case 4: Swapped[0]=*((char*)Addr+3); |
||
16 | Swapped[1]=*((char*)Addr+2); |
||
17 | Swapped[2]=*((char*)Addr+1); |
||
18 | Swapped[3]=*((char*)Addr ); |
||
19 | break; |
||
20 | case 8: Swapped[0]=*((char*)Addr+7); |
||
21 | Swapped[1]=*((char*)Addr+6); |
||
22 | Swapped[2]=*((char*)Addr+5); |
||
23 | Swapped[3]=*((char*)Addr+4); |
||
24 | Swapped[4]=*((char*)Addr+3); |
||
25 | Swapped[5]=*((char*)Addr+2); |
||
26 | Swapped[6]=*((char*)Addr+1); |
||
27 | Swapped[7]=*((char*)Addr ); |
||
28 | break; |
||
29 | case 16:Swapped[0]=*((char*)Addr+15); |
||
30 | Swapped[1]=*((char*)Addr+14); |
||
31 | Swapped[2]=*((char*)Addr+13); |
||
32 | Swapped[3]=*((char*)Addr+12); |
||
33 | Swapped[4]=*((char*)Addr+11); |
||
34 | Swapped[5]=*((char*)Addr+10); |
||
35 | Swapped[6]=*((char*)Addr+9); |
||
36 | Swapped[7]=*((char*)Addr+8); |
||
37 | Swapped[8]=*((char*)Addr+7); |
||
38 | Swapped[9]=*((char*)Addr+6); |
||
39 | Swapped[10]=*((char*)Addr+5); |
||
40 | Swapped[11]=*((char*)Addr+4); |
||
41 | Swapped[12]=*((char*)Addr+3); |
||
42 | Swapped[13]=*((char*)Addr+2); |
||
43 | Swapped[14]=*((char*)Addr+1); |
||
44 | Swapped[15]=*((char*)Addr ); |
||
45 | break; |
||
46 | } |
||
47 | return (void*)Swapped; |
||
48 | } |
||
49 |