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