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. this.Low = Low;
  13. this.High = High;
  14. }
  15. public UInt128(string UInt128Hex)
  16. {
  17. if (UInt128Hex == null || UInt128Hex.Length != 32 || !UInt128Hex.All("0123456789abcdefABCDEF".Contains))
  18. {
  19. throw new ArgumentException("Invalid Hex value!", nameof(UInt128Hex));
  20. }
  21. Low = Convert.ToInt64(UInt128Hex.Substring(16), 16);
  22. High = Convert.ToInt64(UInt128Hex.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. }