//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.Network;
///
/// Number conversion extensions.
///
public static class NumberConversionExtensions
{
///
/// Converts 4 bytes to an 32bit unsigned Integer.
///
/// The lowest.
/// The lower.
/// The higher.
/// The highest.
///
/// The unsigned integer.
///
public static uint MakeDword(byte lowest, byte lower, byte higher, byte highest)
{
return (uint)(MakeWord(lowest, lower) + (MakeWord(higher, highest) << 0x10));
}
///
/// Converts 2 bytes to one 16bit unsigned short.
///
/// The low byte.
/// The high byte.
/// The unsigned short.
public static ushort MakeWord(byte lowByte, byte highByte)
{
return (ushort)(lowByte + ((highByte << 8) & 0xFF00));
}
///
/// Gets the high byte.
///
/// The value.
/// The high byte.
public static byte GetHighByte(this ushort value)
{
return (byte)(value >> 8 & 0xFF);
}
///
/// Gets the low byte.
///
/// The value.
/// The low byte.
public static byte GetLowByte(this ushort value)
{
return (byte)(value & 0xFF);
}
///
/// Converts the signed short to an unsigned short.
///
/// The signed value.
/// The unsigned value.
public static ushort ToUnsigned(this short value)
{
return unchecked((ushort)value);
}
///
/// Converts the unsigned short to a signed short.
///
/// The usigned value.
/// The signed value.
public static short ToSigned(this ushort value)
{
return unchecked((short)value);
}
///
/// Gets the byte of an integer at a specific index position.
///
/// The value.
/// The index.
/// The byte of the integer at the specific index position.
public static byte GetByte(this uint value, int index)
{
return (byte)((value >> (8 * index)) & 0xFF);
}
}