Leaked source code of windows server 2003
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.

30 lines
1.2 KiB

  1. //--------------------------------------------------------------------
  2. // EndianSwap - inline
  3. // Copyright (C) Microsoft Corporation, 1999
  4. //
  5. // Created by: Louis Thomas (louisth), 4-16-99
  6. //
  7. // Inlines to do endian conversion.
  8. // Suck these into a .cpp if you need them.
  9. //
  10. //--------------------------------------------------------------------
  11. static inline unsigned __int16 EndianSwap(unsigned __int16 wSource) {
  12. return (wSource&0x00ff)<<8 | (wSource&0xff00)>>8;
  13. }
  14. //--------------------------------------------------------------------
  15. static inline unsigned __int32 EndianSwap(unsigned __int32 dwSource) {
  16. return
  17. (dwSource&0x000000ff)<<24 | (dwSource&0x0000ff00)<<8
  18. | (dwSource&0x00ff0000)>>8 | (dwSource&0xff000000)>>24;
  19. }
  20. //--------------------------------------------------------------------
  21. static inline unsigned __int64 EndianSwap(unsigned __int64 qwSource) {
  22. return
  23. (qwSource&0x00000000000000ff)<<56 | (qwSource&0x000000000000ff00)<<40
  24. | (qwSource&0x0000000000ff0000)<<24 | (qwSource&0x00000000ff000000)<<8
  25. | (qwSource&0x000000ff00000000)>>8 | (qwSource&0x0000ff0000000000)>>24
  26. | (qwSource&0x00ff000000000000)>>40 | (qwSource&0xff00000000000000)>>56;
  27. }