Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
mri_order.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "mrilib.h"
00008
00009
00010
00011
00012
00013 int mri_short_order(void)
00014 {
00015 union { unsigned char bb[2] ;
00016 short ss ; } fred ;
00017
00018 fred.bb[0] = 1 ; fred.bb[1] = 0 ;
00019
00020 return (fred.ss == 1) ? LSB_FIRST : MSB_FIRST ;
00021 }
00022
00023
00024
00025 int mri_int_order(void)
00026 {
00027 union { unsigned char bb[4] ;
00028 int ii ; } fred ;
00029
00030 fred.bb[0] = 1 ; fred.bb[1] = fred.bb[2] = fred.bb[3] = 0 ;
00031
00032 return (fred.ii == 1) ? LSB_FIRST : MSB_FIRST ;
00033 }
00034
00035
00036
00037 typedef struct { unsigned char a,b ; } twobytes ;
00038
00039 void mri_swap2( int n , short * ar )
00040 {
00041 register int ii ;
00042 register twobytes * tb = (twobytes *) ar ;
00043 register unsigned char tt ;
00044
00045 for( ii=0 ; ii < n ; ii++ ){
00046 tt = tb[ii].a ;
00047 tb[ii].a = tb[ii].b ;
00048 tb[ii].b = tt ;
00049 }
00050 return ;
00051 }
00052
00053
00054
00055 typedef struct { unsigned char a,b,c,d ; } fourbytes ;
00056
00057 void mri_swap4( int n , int * ar )
00058 {
00059 register int ii ;
00060 register fourbytes * tb = (fourbytes *) ar ;
00061 register unsigned char tt , uu ;
00062
00063 for( ii=0 ; ii < n ; ii++ ){
00064 tt = tb[ii].a ;
00065 tb[ii].a = tb[ii].d ;
00066 tb[ii].d = tt ;
00067
00068 uu = tb[ii].b ;
00069 tb[ii].b = tb[ii].c ;
00070 tb[ii].c = uu ;
00071 }
00072 return ;
00073 }