UInt128.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. namespace Ryujinx.HLE.Utilities
  5. {
  6. public struct UInt128
  7. {
  8. public long High { get; private set; }
  9. public long Low { get; private set; }
  10. public UInt128(long low, long high)
  11. {
  12. Low = low;
  13. High = high;
  14. }
  15. public UInt128(string hex)
  16. {
  17. if (hex == null || hex.Length != 32 || !hex.All("0123456789abcdefABCDEF".Contains))
  18. {
  19. throw new ArgumentException("Invalid Hex value!", nameof(hex));
  20. }
  21. Low = Convert.ToInt64(hex.Substring(16), 16);
  22. High = Convert.ToInt64(hex.Substring(0, 16), 16);
  23. }
  24. public void Write(BinaryWriter binaryWriter)
  25. {
  26. binaryWriter.Write(Low);
  27. binaryWriter.Write(High);
  28. }
  29. public override string ToString()
  30. {
  31. return High.ToString("x16") + Low.ToString("x16");
  32. }
  33. public bool IsZero()
  34. {
  35. return (Low | High) == 0;
  36. }
  37. }
  38. }