ConvertUtility.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using System.Text;
  13. using UnityEngine.Assertions;
  14. public static class ConvertUtility
  15. {
  16. public static float IntBitsToFloat(int v)
  17. {
  18. byte[] buf = BitConverter.GetBytes(v);
  19. return BitConverter.ToSingle(buf, 0);
  20. }
  21. public static int FloatToRawIntBits(float v)
  22. {
  23. byte[] buf = BitConverter.GetBytes(v);
  24. return BitConverter.ToInt32(buf, 0);
  25. }
  26. public static string ToString(this float[] data)
  27. {
  28. Assert.IsTrue(data != null);
  29. StringBuilder st = new StringBuilder();
  30. for (int i = 0; i < data.Length; i++)
  31. {
  32. st.Append(data[i] + " ");
  33. }
  34. return st.ToString();
  35. }
  36. }
  37. }