]> www.wagner.pp.ru Git - oss/fgis.git/blob - lib/byteorder.c
First checked in version
[oss/fgis.git] / lib / byteorder.c
1 short swapshort(short x)
2 { return (signed short) (((unsigned short) x)>>8)|(((unsigned short) x)<<8);
3 }
4 long swaplong(long x)
5
6 #define ulx ((unsigned long) x)
7 return (signed long) (((ulx & 0xFF000000)>>24)|((ulx &0xFF0000)>>8)|((ulx & 0xFF00)<<8)|((ulx & 0xFF)<<24));
8 }
9 union doubleconv {double d;
10                   unsigned char b[8];
11                   };
12 double swapdouble(double x)
13 { union doubleconv tmp1,tmp2;
14   int i,j;
15   tmp1.d=x;
16    for (i=0,j=7;i<8;tmp2.b[j--]=tmp1.b[i++]);
17    return tmp2.d;
18  }