#include "dcwSwap.h" /******************************************************************** * Function Name: dcwSwapBytes * Author : Dan Wilkinson & Grigoriy Ushomirskiy * Date : August 24, 1992 * Function : Swap byte order of a 16-bit or 32-bit integer. *********************************************************************/ short dcwSwapBytes( char *in, short Bytes ) { char c; #ifdef SWAPBYTES switch( Bytes ){ case TWO_BYTES: c=*in; *in=*(in+1); *(in+1)=c; return( GOOD); case FOUR_BYTES: c=*in; *in=*(in+3); *(in+3)=c; c=*(in+1); *(in+1)=*(in+2); *(in+2)=c; return( GOOD ); } return( BAD ); #else return( GOOD ); #endif } /******************************************************************** * Function Name: dcwSwapShort * Author : Dan Wilkinson & Grigoriy Ushomirskiy * Date : November 10, 1995 * Function : Return a 16-bit integer with the two bytes in reverse order. *********************************************************************/ short dcwSwapShort( short Value ) { char c, *in; in = (char *) &Value; #ifdef SWAPBYTES c=*in; /* Value in left byte stored in c */ *in=*(in+1); /* New Left byte value set to Old right byte value */ *(in+1)=c; /* New Right byte value set to Old left byte value sorted in c */ #endif return( Value ); } /******************************************************************** * Function Name: dcwSwapLong * Author : Dan Wilkinson & Grigoriy Ushomirskiy * Date : November 10, 1995 * Function : Return a 32-bit integer with the four bytes in reverse order. *********************************************************************/ long dcwSwapLong( long Value ) { char c, *in; in = (char *) &Value; #ifdef SWAPBYTES c=*in; *in=*(in+3); *(in+3)=c; c=*(in+1); *(in+1)=*(in+2); *(in+2)=c; #endif return( Value ); }