From 041cadce2da3e85d76b8a9955c096e64ca73ccbd Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Sun, 26 May 2024 21:27:01 +0800 Subject: [PATCH] =?UTF-8?q?short=E6=94=AF=E6=8C=818bit=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HybirdFrameworkCore/Utils/BitUtls.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/HybirdFrameworkCore/Utils/BitUtls.cs b/HybirdFrameworkCore/Utils/BitUtls.cs index 075bb4c..8c4f63a 100644 --- a/HybirdFrameworkCore/Utils/BitUtls.cs +++ b/HybirdFrameworkCore/Utils/BitUtls.cs @@ -243,17 +243,23 @@ public static class BitUtls 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); + if (sub.Length == 1) + { + return Convert.ToUInt16(sub[0]); + } return BitConverter.ToUInt16(sub, 0); } 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); + if (sub.Length == 1) + { + return Convert.ToInt16(sub[0]); + } return BitConverter.ToInt16(sub, 0); }