Rev 1063 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "endn.h"
/******************************************************************************
FUNCTION: SwapEndian
PURPOSE: Swap the byte order of a structure
EXAMPLE: float F=123.456;; SWAP_FLOAT(F);
******************************************************************************/
void *SwapEndian(void* Addr, const int Nb) {
static char Swapped[16];
switch (Nb) {
case 2: Swapped[0]=*((char*)Addr+1);
Swapped[1]=*((char*)Addr );
break;
case 4: Swapped[0]=*((char*)Addr+3);
Swapped[1]=*((char*)Addr+2);
Swapped[2]=*((char*)Addr+1);
Swapped[3]=*((char*)Addr );
break;
case 8: Swapped[0]=*((char*)Addr+7);
Swapped[1]=*((char*)Addr+6);
Swapped[2]=*((char*)Addr+5);
Swapped[3]=*((char*)Addr+4);
Swapped[4]=*((char*)Addr+3);
Swapped[5]=*((char*)Addr+2);
Swapped[6]=*((char*)Addr+1);
Swapped[7]=*((char*)Addr );
break;
case 16:Swapped[0]=*((char*)Addr+15);
Swapped[1]=*((char*)Addr+14);
Swapped[2]=*((char*)Addr+13);
Swapped[3]=*((char*)Addr+12);
Swapped[4]=*((char*)Addr+11);
Swapped[5]=*((char*)Addr+10);
Swapped[6]=*((char*)Addr+9);
Swapped[7]=*((char*)Addr+8);
Swapped[8]=*((char*)Addr+7);
Swapped[9]=*((char*)Addr+6);
Swapped[10]=*((char*)Addr+5);
Swapped[11]=*((char*)Addr+4);
Swapped[12]=*((char*)Addr+3);
Swapped[13]=*((char*)Addr+2);
Swapped[14]=*((char*)Addr+1);
Swapped[15]=*((char*)Addr );
break;
}
return (void*)Swapped;
}