mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-02-04 05:36:05 +00:00
86 lines
2.7 KiB
C#
86 lines
2.7 KiB
C#
namespace SabreTools.IO.Numerics
|
|
{
|
|
/// <summary>
|
|
/// Both-endian 8-bit unsigned value
|
|
/// </summary>
|
|
public sealed class BothUInt8(byte le, byte be) : BothEndian<byte>(le, be)
|
|
{
|
|
#region Operators
|
|
|
|
public static BothUInt8 operator +(BothUInt8 a, BothUInt8 b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian + b.LittleEndian);
|
|
byte be = (byte)(a.BigEndian + b.BigEndian);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static BothUInt8 operator +(BothUInt8 a, byte b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian + b);
|
|
byte be = (byte)(a.BigEndian + b);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static BothUInt8 operator -(BothUInt8 a, BothUInt8 b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian - b.LittleEndian);
|
|
byte be = (byte)(a.BigEndian - b.BigEndian);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static BothUInt8 operator -(BothUInt8 a, byte b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian - b);
|
|
byte be = (byte)(a.BigEndian - b);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static BothUInt8 operator *(BothUInt8 a, BothUInt8 b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian * b.LittleEndian);
|
|
byte be = (byte)(a.BigEndian * b.BigEndian);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static BothUInt8 operator *(BothUInt8 a, byte b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian * b);
|
|
byte be = (byte)(a.BigEndian * b);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static BothUInt8 operator /(BothUInt8 a, BothUInt8 b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian / b.LittleEndian);
|
|
byte be = (byte)(a.BigEndian / b.BigEndian);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static BothUInt8 operator /(BothUInt8 a, byte b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian / b);
|
|
byte be = (byte)(a.BigEndian / b);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static BothUInt8 operator ^(BothUInt8 a, BothUInt8 b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian ^ b.LittleEndian);
|
|
byte be = (byte)(a.BigEndian ^ b.BigEndian);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static BothUInt8 operator ^(BothUInt8 a, byte b)
|
|
{
|
|
byte le = (byte)(a.LittleEndian ^ b);
|
|
byte be = (byte)(a.BigEndian ^ b);
|
|
return new BothUInt8(le, be);
|
|
}
|
|
|
|
public static implicit operator BothUInt8(byte val)
|
|
=> new(val, val);
|
|
|
|
#endregion
|
|
}
|
|
}
|