Re: [ROOT] Big endian

From: Steve Lautenschlager (srlautenschlager@hotmail.com)
Date: Tue Oct 03 2000 - 21:24:51 MEST


Sara,

Here is a C function which will do a standard endian byte swap.  If it's not 
exactly what you need it will probably be close.

Cheers,
Steve


/******************************************************************
/- file: endian_swap.c
/-
/-
/- usage: endian_swap(char * pdata, int dsize, int nelements)
/---------
/-
/- inputs:
/---------
/- char * pdata = pointer to data to be converted
/- int dsize    = size of datatype (in bytes) stored at memory location
/- int nelements = number of data elements of size dsize to process
/-
/-
/- Modification Log:
/-------------------
/- 23 dec 99	S.Lautenschlager		Created
/-
/-******************************************************************/

void endian_swap(char * pdata, int dsize, int nelements)

{

	int i,j,indx;
	char tempbyte;

	if (dsize <= 1) return;

	for (i=0; i<nelements; i++)
	{
		indx = dsize;
		for (j=0; j<dsize/2; j++)
		{
			tempbyte = pdata[j];
			indx = indx - 1;
			pdata[j] = pdata[indx];
			pdata[indx] = tempbyte;
		}

		pdata = pdata + dsize;
	}

	return;

}


_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:34 MET