Files
SabreTools.IO/SabreTools.Numerics/BothUInt8.cs
Matt Nadareski d614379cf5 Libraries
This change looks dramatic, but it's just separating out the already-split namespaces into separate top-level folders. In theory, every single one could be built into their own Nuget package. `SabreTools.IO.Meta` builds the normal Nuget package that is used by all other projects and includes all namespaces. `SabreTools.IO` builds to `SabreTools.IO.Common` to avoid overwriting issues on publish.
2026-03-21 13:55:42 -04:00

130 lines
3.9 KiB
C#

namespace SabreTools.Numerics
{
/// <summary>
/// Both-endian 8-bit unsigned value
/// </summary>
public sealed class BothUInt8(byte le, byte be) : BothEndian<byte>(le, be)
{
public static implicit operator BothUInt8(byte val)
=> new(val, val);
#region Arithmetic Unary Operators
public static BothUInt8 operator ++(BothUInt8 a)
{
byte le = (byte)(a.LittleEndian + 1);
byte be = (byte)(a.BigEndian + 1);
return new BothUInt8(le, be);
}
public static BothUInt8 operator --(BothUInt8 a)
{
byte le = (byte)(a.LittleEndian - 1);
byte be = (byte)(a.BigEndian - 1);
return new BothUInt8(le, be);
}
#endregion
#region Arithmetic Binary 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, 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, 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, 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, BothUInt8 b)
{
byte le = (byte)(a.LittleEndian - b.LittleEndian);
byte be = (byte)(a.BigEndian - b.BigEndian);
return new BothUInt8(le, be);
}
#endregion
#region Bitwise Unary Operators
public static BothUInt8 operator ~(BothUInt8 a)
{
byte le = (byte)~a.LittleEndian;
byte be = (byte)~a.BigEndian;
return new BothUInt8(le, be);
}
#endregion
#region Shift Binary 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, 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, BothUInt8 b)
{
byte le = (byte)(a.LittleEndian >>> b.LittleEndian);
byte be = (byte)(a.BigEndian >>> b.BigEndian);
return new BothUInt8(le, be);
}
#endregion
#region Bitwise Binary 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, 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, BothUInt8 b)
{
byte le = (byte)(a.LittleEndian ^ b.LittleEndian);
byte be = (byte)(a.BigEndian ^ b.BigEndian);
return new BothUInt8(le, be);
}
#endregion
}
}