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