You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
785 B

/************************************************************************/
/* 字节顺序交换 */
/************************************************************************/
#ifndef __BSWAP_H__
#define __BSWAP_H__
/* 16bit的字节顺序交换 */
static inline uint16_t bswap_16(uint16_t x)
{
return (x >> 8) | (x << 8);
}
/* 32bit的字节顺序交换 */
static inline uint32_t bswap_32(uint32_t x)
{
x = ((x << 8) &0xFF00FF00) | ((x >> 8) &0x00FF00FF);
return (x >> 16) | (x << 16);
}
// be2me ... BigEndian to MachineEndian
// le2me ... LittleEndian to MachineEndian
#define be2me_16(x) bswap_16(x)
#define be2me_32(x) bswap_32(x)
#define le2me_16(x) (x)
#define le2me_32(x) (x)
#endif