UInt128.cs 1.1 KB

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