Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
niml_byteorder.c
Go to the documentation of this file.00001 #include "niml_private.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 int NI_byteorder(void)
00015 {
00016 union { unsigned char bb[2] ;
00017 short ss ; } fred ;
00018
00019 fred.bb[0] = 1 ; fred.bb[1] = 0 ;
00020
00021 return (fred.ss == 1) ? NI_LSB_FIRST : NI_MSB_FIRST ;
00022 }
00023
00024
00025
00026
00027 typedef struct { unsigned char a,b ; } twobytes ;
00028
00029
00030
00031
00032
00033 void NI_swap2( int n , void *ar )
00034 {
00035 register int ii ;
00036 register twobytes *tb = (twobytes *) ar ;
00037 register unsigned char tt ;
00038
00039 for( ii=0 ; ii < n ; ii++ ){
00040 tt = tb[ii].a ; tb[ii].a = tb[ii].b ; tb[ii].b = tt ;
00041 }
00042 return ;
00043 }
00044
00045
00046
00047
00048 typedef struct { unsigned char a,b,c,d ; } fourbytes ;
00049
00050
00051
00052
00053
00054 void NI_swap4( int n , void *ar )
00055 {
00056 register int ii ;
00057 register fourbytes *tb = (fourbytes *) ar ;
00058 register unsigned char tt , uu ;
00059
00060 for( ii=0 ; ii < n ; ii++ ){
00061 tt = tb[ii].a ; tb[ii].a = tb[ii].d ; tb[ii].d = tt ;
00062 uu = tb[ii].b ; tb[ii].b = tb[ii].c ; tb[ii].c = uu ;
00063 }
00064 return ;
00065 }
00066
00067
00068
00069
00070 typedef struct { unsigned char a,b,c,d , e,f,g,h ; } eightbytes ;
00071
00072
00073
00074
00075
00076 void NI_swap8( int n , void *ar )
00077 {
00078 register int ii ;
00079 register eightbytes *tb = (eightbytes *) ar ;
00080 register unsigned char tt , uu , vv , ww ;
00081
00082 for( ii=0 ; ii < n ; ii++ ){
00083 tt = tb[ii].a ; tb[ii].a = tb[ii].h ; tb[ii].h = tt ;
00084 uu = tb[ii].b ; tb[ii].b = tb[ii].g ; tb[ii].g = uu ;
00085 vv = tb[ii].c ; tb[ii].c = tb[ii].f ; tb[ii].f = vv ;
00086 ww = tb[ii].d ; tb[ii].d = tb[ii].e ; tb[ii].e = ww ;
00087 }
00088 return ;
00089 }