powerfun-unity/Assets/Scripts/Devices/ByteExtensions.cs

35 lines
1.1 KiB
C#
Raw Normal View History

2021-04-01 09:33:19 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices
{
public static class ByteExtensions
{
public static byte GetDifference(this byte currentVal, byte previousVal)
{
byte num = (byte)((uint)currentVal - (uint)previousVal);
if ((int)previousVal > (int)currentVal)
num = (byte)((int)byte.MaxValue + (int)num + 1);
return num;
}
public static bool Contains(this IEnumerable<byte[]> enumerable, byte[] bytes)
{
return Enumerable.Any<byte[]>(enumerable, (Func<byte[], bool>)(x => Enumerable.SequenceEqual<byte>((IEnumerable<byte>)x, (IEnumerable<byte>)bytes)));
}
public static bool IsFlagSet(this byte value, byte flag)
{
return ((uint)value & (uint)flag) > 0U;
}
public static bool IsFlagSetAtPosition(this byte value, byte position)
{
return ((uint)value & 1U << (int)position) > 0U;
}
}
}