|
|
@ -243,17 +243,23 @@ public static class BitUtls
|
|
|
|
|
|
|
|
|
|
|
|
public static ushort Byte2UInt16(byte[] bytes, int startBit, int length)
|
|
|
|
public static ushort Byte2UInt16(byte[] bytes, int startBit, int length)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (length < 9 || length > 16) throw new ArgumentException("length should be less then 17 and greater then 8");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sub = Sub(bytes, startBit, length);
|
|
|
|
var sub = Sub(bytes, startBit, length);
|
|
|
|
|
|
|
|
if (sub.Length == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Convert.ToUInt16(sub[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
return BitConverter.ToUInt16(sub, 0);
|
|
|
|
return BitConverter.ToUInt16(sub, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static short Byte2Int16(byte[] bytes, int startBit, int length)
|
|
|
|
public static short Byte2Int16(byte[] bytes, int startBit, int length)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (length < 9 || length > 16) throw new ArgumentException("length should be less then 17 and greater then 8");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sub = Sub(bytes, startBit, length);
|
|
|
|
var sub = Sub(bytes, startBit, length);
|
|
|
|
|
|
|
|
if (sub.Length == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Convert.ToInt16(sub[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
return BitConverter.ToInt16(sub, 0);
|
|
|
|
return BitConverter.ToInt16(sub, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|