TigerEmu/Utils/ByteUtils.cs

24 lines
625 B
C#
Raw Normal View History

2023-09-23 11:11:07 +00:00
namespace Tiger.Utils;
public static class ByteUtils
{
public static int GetInt32(byte[] array)
{
return (array[0] << 24) | (array[1] << 16) | (array[2] << 8) | array[3];
}
2023-09-23 11:11:07 +00:00
public static short GetInt16(byte[] array)
{
return (short)((array[0] << 8) | array[1]);
}
public static IEnumerable<byte> Int32ToArray(int value)
{
return new[] { (byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)value };
}
public static IEnumerable<byte> Int16ToArray(short value)
{
return new[] { (byte)(value >> 8), (byte)value };
}
}