home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- int needmotorolaorder = 1;
-
- static int whatwehave = -1;
-
- void
- initorder()
- {
- int x = 0;
-
- ((char *)&x)[3] = 1;
- if(x == 1)
- whatwehave = 1;
- else
- whatwehave = 0;
- }
-
- unsigned long
- LongSwap(x)
- unsigned long x;
- {
- if(whatwehave == -1)
- initorder();
- if(whatwehave == needmotorolaorder)
- return;
- x = (x>>16 & 0x0000ffff) | (x<<16 & 0xffff0000);
- x = (x>> 8 & 0x00ff00ff) | (x<< 8 & 0xff00ff00);
- return(x);
- }
-
- unsigned short
- ShortSwap(x)
- unsigned short x;
- {
- if(whatwehave == -1)
- initorder();
- if(whatwehave == needmotorolaorder)
- return;
- x = (x>> 8 & 0x00ff) | (x<< 8 & 0xff00);
- return(x);
- }
-