1
0

byteswap.h 590 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef _BYTESWAP_H
  2. #define _BYTESWAP_H
  3. #include <stdint.h>
  4. #if __STDC_VERSION__ >= 199901L
  5. inline
  6. #endif
  7. static uint16_t __bswap_16(uint16_t __x)
  8. {
  9. return __x<<8 | __x>>8;
  10. }
  11. #if __STDC_VERSION__ >= 199901L
  12. inline
  13. #endif
  14. static uint32_t __bswap_32(uint32_t __x)
  15. {
  16. return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
  17. }
  18. #if __STDC_VERSION__ >= 199901L
  19. inline
  20. #endif
  21. static uint64_t __bswap_64(uint64_t __x)
  22. {
  23. return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32);
  24. }
  25. #define bswap_16(x) __bswap_16(x)
  26. #define bswap_32(x) __bswap_32(x)
  27. #define bswap_64(x) __bswap_64(x)
  28. #endif