powerfun-unity/Assets/Scripts/Devices/Ble/BitConvertHelper.cs
2021-09-28 11:27:24 +08:00

53 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts
{
public static class BitConvertHelper
{
public static byte Lsn(byte b)
{
return (byte)(b & 15);
}
// Token: 0x060032F7 RID: 13047 RVA: 0x000C22C3 File Offset: 0x000C04C3
public static byte Lsn(byte[] bytes, int index)
{
return BitConvertHelper.Lsn(bytes[index]);
}
public static byte ToUInt8(byte[] bytes, int index)
{
return bytes[index];
}
// Token: 0x060032FB RID: 13051 RVA: 0x000C22E8 File Offset: 0x000C04E8
public static ushort ToUInt12(byte[] bytes, int index)
{
return (ushort)((int)bytes[index] + ((int)BitConvertHelper.Lsn(bytes[index + 1]) << 8));
}
public static ushort ToUInt16(byte[] bytes, int startIndex)
{
return BitConverter.ToUInt16(bytes, startIndex);
}
public static short ToInt16(byte[] bytes, int startIndex)
{
return BitConverter.ToInt16(bytes, startIndex);
}
public static uint ToUInt32(byte[] bytes, int startIndex)
{
return BitConverter.ToUInt32(bytes, startIndex);
}
public static uint ToUInt24(byte[] bytes, int startIndex)
{
return (uint)((int)bytes[startIndex] | (int)bytes[startIndex + 1] << 8 | (int)bytes[startIndex + 2] << 16);
}
}
}