root/Whitix/trunk/include/byteswap.h

Revision 1973, 457 bytes (checked in by mwhitworth, 3 years ago)

Add word swap functions. (USB stack to be committed soon).

Line 
1#ifndef BYTESWAP_H
2#define BYTESWAP_H
3
4#include <typedefs.h>
5
6static inline DWORD BeToCpu32(DWORD x)
7{
8        unsigned char* p=(unsigned char*)&x;
9
10        return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
11}
12
13static inline DWORD CpuToBe32(DWORD x)
14{
15        return BeToCpu32(x);
16}
17
18static inline WORD BeToCpu16(WORD x)
19{
20        unsigned char* p = (unsigned char*)&x;
21       
22        return ((p[0] << 16) | p[1]);
23}
24
25static inline WORD CpuToBe16(WORD x)
26{
27        return BeToCpu16(x);
28}
29
30#endif
Note: See TracBrowser for help on using the browser.