LuaUInt64.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using UnityEngine;
  3. public class LuaUInt64
  4. {
  5. public static byte[] Make(UInt32 high, UInt32 low)
  6. {
  7. UInt64 uint64_value = high;
  8. uint64_value = ((uint64_value << 32) | low);
  9. return BitConverter.GetBytes(uint64_value);
  10. }
  11. public static byte[] FromString(string str)
  12. {
  13. str = str.Replace("#", "");
  14. UInt64 v;
  15. UInt64.TryParse(str, out v);
  16. return BitConverter.GetBytes(v);
  17. }
  18. public static byte[] And(byte[] left, byte[] right)
  19. {
  20. ulong uint64_value_l = BitConverter.ToUInt64(left, 0);
  21. ulong uint64_value_r = BitConverter.ToUInt64(right, 0);
  22. return BitConverter.GetBytes(uint64_value_l & uint64_value_r);
  23. }
  24. public static byte[] Or(byte[] left, byte[] right)
  25. {
  26. ulong uint64_value_l = BitConverter.ToUInt64(left, 0);
  27. ulong uint64_value_r = BitConverter.ToUInt64(right, 0);
  28. return BitConverter.GetBytes(uint64_value_l | uint64_value_r);
  29. }
  30. public static byte[] Xor(byte[] left, byte[] right)
  31. {
  32. ulong uint64_value_l = BitConverter.ToUInt64(left, 0);
  33. ulong uint64_value_r = BitConverter.ToUInt64(right, 0);
  34. return BitConverter.GetBytes(uint64_value_l ^ uint64_value_r);
  35. }
  36. public static byte[] FromDouble(double v)
  37. {
  38. return BitConverter.GetBytes((ulong)v);
  39. }
  40. public static double ToDouble(byte[] v)
  41. {
  42. return (double)BitConverter.ToUInt64(v, 0);
  43. }
  44. public static string ToString(byte[] v)
  45. {
  46. ulong uint64_value = BitConverter.ToUInt64(v, 0);
  47. return uint64_value.ToString();
  48. }
  49. public static byte[] UInt64ToBytes(UInt64 v)
  50. {
  51. return BitConverter.GetBytes(v);
  52. }
  53. public static UInt64 BytesToUInt64(byte[] v)
  54. {
  55. return BitConverter.ToUInt64(v, 0);
  56. }
  57. }