2018-10-07 14:13:46 +01:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Utilities
|
|
|
|
{
|
|
|
|
public struct UInt128
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
public long High { get; private set; }
|
|
|
|
public long Low { get; private set; }
|
2018-10-07 14:13:46 +01:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public UInt128(long low, long high)
|
2018-10-07 14:13:46 +01:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
Low = low;
|
|
|
|
High = high;
|
2018-10-07 14:13:46 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public UInt128(string hex)
|
2018-10-07 14:13:46 +01:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
if (hex == null || hex.Length != 32 || !hex.All("0123456789abcdefABCDEF".Contains))
|
2018-10-07 14:13:46 +01:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
throw new ArgumentException("Invalid Hex value!", nameof(hex));
|
2018-10-07 14:13:46 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
Low = Convert.ToInt64(hex.Substring(16), 16);
|
|
|
|
High = Convert.ToInt64(hex.Substring(0, 16), 16);
|
2018-10-07 14:13:46 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public void Write(BinaryWriter binaryWriter)
|
2018-10-07 14:13:46 +01:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
binaryWriter.Write(Low);
|
|
|
|
binaryWriter.Write(High);
|
2018-10-07 14:13:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return High.ToString("x16") + Low.ToString("x16");
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsZero()
|
|
|
|
{
|
|
|
|
return (Low | High) == 0;
|
|
|
|
}
|
|
|
|
}
|
2018-10-13 22:29:49 +01:00
|
|
|
}
|