Files
SabreTools.IO/SabreTools.IO/Numerics/BothUInt8.cs
2025-10-27 14:02:52 -04:00

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
}
}