Rev 261 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1063 | tullio | 1 | |
2 | /* |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
16 | * |
||
17 | */ |
||
18 | |||
261 | giacomo | 19 | #include "endn.h" |
20 | |||
21 | /****************************************************************************** |
||
22 | FUNCTION: SwapEndian |
||
23 | PURPOSE: Swap the byte order of a structure |
||
24 | EXAMPLE: float F=123.456;; SWAP_FLOAT(F); |
||
25 | ******************************************************************************/ |
||
26 | |||
27 | void *SwapEndian(void* Addr, const int Nb) { |
||
28 | static char Swapped[16]; |
||
29 | switch (Nb) { |
||
30 | case 2: Swapped[0]=*((char*)Addr+1); |
||
31 | Swapped[1]=*((char*)Addr ); |
||
32 | break; |
||
33 | case 4: Swapped[0]=*((char*)Addr+3); |
||
34 | Swapped[1]=*((char*)Addr+2); |
||
35 | Swapped[2]=*((char*)Addr+1); |
||
36 | Swapped[3]=*((char*)Addr ); |
||
37 | break; |
||
38 | case 8: Swapped[0]=*((char*)Addr+7); |
||
39 | Swapped[1]=*((char*)Addr+6); |
||
40 | Swapped[2]=*((char*)Addr+5); |
||
41 | Swapped[3]=*((char*)Addr+4); |
||
42 | Swapped[4]=*((char*)Addr+3); |
||
43 | Swapped[5]=*((char*)Addr+2); |
||
44 | Swapped[6]=*((char*)Addr+1); |
||
45 | Swapped[7]=*((char*)Addr ); |
||
46 | break; |
||
47 | case 16:Swapped[0]=*((char*)Addr+15); |
||
48 | Swapped[1]=*((char*)Addr+14); |
||
49 | Swapped[2]=*((char*)Addr+13); |
||
50 | Swapped[3]=*((char*)Addr+12); |
||
51 | Swapped[4]=*((char*)Addr+11); |
||
52 | Swapped[5]=*((char*)Addr+10); |
||
53 | Swapped[6]=*((char*)Addr+9); |
||
54 | Swapped[7]=*((char*)Addr+8); |
||
55 | Swapped[8]=*((char*)Addr+7); |
||
56 | Swapped[9]=*((char*)Addr+6); |
||
57 | Swapped[10]=*((char*)Addr+5); |
||
58 | Swapped[11]=*((char*)Addr+4); |
||
59 | Swapped[12]=*((char*)Addr+3); |
||
60 | Swapped[13]=*((char*)Addr+2); |
||
61 | Swapped[14]=*((char*)Addr+1); |
||
62 | Swapped[15]=*((char*)Addr ); |
||
63 | break; |
||
64 | } |
||
65 | return (void*)Swapped; |
||
66 | } |
||
67 |