Back to index

radiance  4R0+20100331
byteswap.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char RCSid[] = "$Id: byteswap.c,v 3.1 2006/12/23 17:27:45 greg Exp $";
00003 #endif
00004 /*
00005  * Byte swapping routines
00006  *
00007  * External symbols declared in rtio.h
00008  */
00009 
00010 #include "copyright.h"
00011 #include "rtio.h"
00012 
00013 void
00014 swap16(              /* swap n 16-bit words */
00015        register char  *wp,
00016        int  n
00017 )
00018 {
00019        register int  t;
00020 
00021        while (n-- > 0) {
00022               t = wp[0]; wp[0] = wp[1]; wp[1] = t;
00023               wp += 2;
00024        }
00025 }
00026 
00027 
00028 void
00029 swap32(              /* swap n 32-bit words */
00030        register char  *wp,
00031        int  n
00032 )
00033 {
00034        register int  t;
00035 
00036        while (n-- > 0) {
00037               t = wp[0]; wp[0] = wp[3]; wp[3] = t;
00038               t = wp[1]; wp[1] = wp[2]; wp[2] = t;
00039               wp += 4;
00040        }
00041 }
00042 
00043 
00044 void
00045 swap64(              /* swap n 64-bit words */
00046        register char  *wp,
00047        int  n
00048 )
00049 {
00050        register int  t;
00051 
00052        while (n-- > 0) {
00053               t = wp[0]; wp[0] = wp[7]; wp[7] = t;
00054               t = wp[1]; wp[1] = wp[6]; wp[6] = t;
00055               t = wp[2]; wp[2] = wp[5]; wp[5] = t;
00056               t = wp[3]; wp[3] = wp[4]; wp[4] = t;
00057               wp += 8;
00058        }
00059 }
00060