Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

endian.c

Go to the documentation of this file.
00001 /*! \file endian.c
00002     This file implements various utilities to swap between little/big endian.
00003  */
00004 
00005 #include "my_endian.h"
00006 
00007 
00008 /*! \brief Swap a 2 byte signed integer.
00009     \param tni2 Pointer to the 2 byte signed integer to swap.
00010  */
00011 
00012 void swap_short_2(short *tni2)
00013 {
00014  *tni2=(((*tni2>>8)&0xff) | ((*tni2&0xff)<<8));  
00015 }
00016 
00017 /*! \brief Swap a 2 byte unsigned integer.
00018     \param tni2 Pointer to the 2 byte unsigned integer to swap.
00019  */
00020 
00021 void swap_u_short_2(unsigned short *tni2) 
00022 {
00023  *tni2=(((*tni2>>8)&0xff) | ((*tni2&0xff)<<8));  
00024 }
00025 
00026 /*! \brief Swap a 4 byte signed integer.
00027     \param tni4 Pointer to the 4 byte signed integer to swap.
00028  */
00029 
00030 void swap_int_4(int *tni4) 
00031 {
00032  *tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
00033             ((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));  
00034 }
00035 
00036 /*! \brief Swap a 4 byte unsigned integer.
00037     \param tni4 Pointer to the 4 byte unsigned integer to swap.
00038  */
00039 
00040 void swap_u_int_4(unsigned int *tni4) 
00041 {
00042  *tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
00043             ((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));  
00044 }
00045 
00046 /*! \brief Swap a 4 byte signed long integer.
00047     \param tni4 Pointer to the 4 byte signed long integer to swap.
00048  */
00049 
00050 void swap_long_4(long *tni4)
00051 {
00052  *tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
00053             ((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));  
00054 }
00055 
00056 /*! \brief Swap a 4 byte unsigned long integer.
00057     \param tni4 Pointer to the 4 byte unsigned long integer to swap.
00058  */
00059 
00060 void swap_u_long_4(unsigned long *tni4) 
00061 {
00062  *tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
00063             ((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));  
00064 }
00065 
00066 /*! \brief Swap a 4 byte floating point number.
00067     \param tnf4 Pointer to the 4 byte floating point number to swap.
00068  */
00069 
00070 void swap_float_4(float *tnf4) 
00071 {
00072  int *tni4=(int *)tnf4;
00073  *tni4=(((*tni4>>24)&0xff) | ((*tni4&0xff)<<24) |
00074             ((*tni4>>8)&0xff00) | ((*tni4&0xff00)<<8));  
00075 }
00076 
00077 /*! \brief Swap a 8 byte double number.
00078         \param tndd8 Pointer to the 8 byte double number to swap.
00079  */
00080 
00081 void swap_double_8(double *tndd8) 
00082 {
00083   char *tnd8=(char *)tndd8;
00084   char tnc;
00085 
00086   tnc=*tnd8;
00087   *tnd8=*(tnd8+7);
00088   *(tnd8+7)=tnc;
00089 
00090   tnc=*(tnd8+1);
00091   *(tnd8+1)=*(tnd8+6);
00092   *(tnd8+6)=tnc;
00093 
00094   tnc=*(tnd8+2);
00095   *(tnd8+2)=*(tnd8+5);
00096   *(tnd8+5)=tnc;
00097 
00098   tnc=*(tnd8+3);
00099   *(tnd8+3)=*(tnd8+4);
00100   *(tnd8+4)=tnc;
00101 }
00102 
00103 

Generated on Thu Apr 3 16:23:43 2003 for Common_C_libraries by doxygen1.3-rc1