2018-10-07 09:13:46 -04:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Utilities
|
|
|
|
{
|
|
|
|
public struct UInt128
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
public long High { get; private set; }
|
|
|
|
public long Low { get; private set; }
|
2018-10-07 09:13:46 -04:00
|
|
|
|
2019-06-15 18:35:38 -04:00
|
|
|
public bool IsNull => (Low | High) == 0;
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public UInt128(long low, long high)
|
2018-10-07 09:13:46 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
Low = low;
|
|
|
|
High = high;
|
2018-10-07 09:13:46 -04:00
|
|
|
}
|
|
|
|
|
2019-06-15 18:35:38 -04:00
|
|
|
public UInt128(byte[] bytes)
|
|
|
|
{
|
|
|
|
Low = BitConverter.ToInt64(bytes, 0);
|
|
|
|
High = BitConverter.ToInt64(bytes, 8);
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public UInt128(string hex)
|
2018-10-07 09:13:46 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
if (hex == null || hex.Length != 32 || !hex.All("0123456789abcdefABCDEF".Contains))
|
2018-10-07 09:13:46 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
throw new ArgumentException("Invalid Hex value!", nameof(hex));
|
2018-10-07 09:13:46 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
Low = Convert.ToInt64(hex.Substring(16), 16);
|
|
|
|
High = Convert.ToInt64(hex.Substring(0, 16), 16);
|
2018-10-07 09:13:46 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public void Write(BinaryWriter binaryWriter)
|
2018-10-07 09:13:46 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
binaryWriter.Write(Low);
|
|
|
|
binaryWriter.Write(High);
|
2018-10-07 09:13:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return High.ToString("x16") + Low.ToString("x16");
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsZero()
|
|
|
|
{
|
|
|
|
return (Low | High) == 0;
|
|
|
|
}
|
|
|
|
}
|
2019-06-15 18:35:38 -04:00
|
|
|
}
|