dsi_convert.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2014
  6. All rights reserved.
  7. */
  8. #include "types.h"
  9. #include "dsi_convert.h"
  10. //////////////////////////////////////////////////////////////////////////////////
  11. // Public Functions
  12. //////////////////////////////////////////////////////////////////////////////////
  13. ///////////////////////////////////////////////////////////////////////
  14. void Convert_USHORT_To_Bytes(USHORT usNum, UCHAR* ucByte1, UCHAR* ucByte0)
  15. {
  16. if(ucByte0 != NULL)
  17. *ucByte0 = (UCHAR)(usNum);
  18. if(ucByte1 != NULL)
  19. *ucByte1 = (UCHAR)(usNum >> 8);
  20. return;
  21. }
  22. ///////////////////////////////////////////////////////////////////////
  23. USHORT Convert_Bytes_To_USHORT(UCHAR ucByte1, UCHAR ucByte0)
  24. {
  25. USHORT usReturn;
  26. usReturn = (ucByte0)+(ucByte1 << 8);
  27. return usReturn;
  28. }
  29. ///////////////////////////////////////////////////////////////////////
  30. void Convert_ULONG_To_Bytes(ULONG ulNum, UCHAR* ucByte3, UCHAR* ucByte2, UCHAR* ucByte1, UCHAR* ucByte0)
  31. {
  32. if(ucByte0 != NULL)
  33. *ucByte0 = (UCHAR)(ulNum);
  34. if(ucByte1 != NULL)
  35. *ucByte1 = (UCHAR)(ulNum >> 8);
  36. if(ucByte2 != NULL)
  37. *ucByte2 = (UCHAR)(ulNum >> 16);
  38. if(ucByte3 != NULL)
  39. *ucByte3 = (UCHAR)(ulNum >> 24);
  40. return;
  41. }
  42. ///////////////////////////////////////////////////////////////////////
  43. ULONG Convert_Bytes_To_ULONG(UCHAR ucByte3, UCHAR ucByte2, UCHAR ucByte1, UCHAR ucByte0)
  44. {
  45. ULONG ulReturn;
  46. ulReturn = (ucByte0)+(ucByte1 << 8)+(ucByte2 << 16)+(ucByte3 << 24);
  47. return ulReturn;
  48. }