|
|
@@ -6,7 +6,6 @@ using System.Diagnostics;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using System.Runtime.InteropServices;
|
|
|
-using System.Text;
|
|
|
using WCS.Entity;
|
|
|
|
|
|
namespace WCS.Core
|
|
|
@@ -239,7 +238,7 @@ namespace WCS.Core
|
|
|
if (type == typeof(bool))
|
|
|
size = 1;
|
|
|
var data = ReadBytes(ref bitStart, size);
|
|
|
- if (reverse && type != typeof(float))
|
|
|
+ if (reverse)
|
|
|
data = data.Reverse().ToArray();
|
|
|
if (type == typeof(byte))
|
|
|
{
|
|
|
@@ -279,8 +278,7 @@ namespace WCS.Core
|
|
|
}
|
|
|
else if (type == typeof(float))
|
|
|
{
|
|
|
- BitConverter.ToSingle(data, 0);
|
|
|
- return GetToTwo(data);
|
|
|
+ return BitConverter.ToSingle(data, 0);
|
|
|
}
|
|
|
else if (type == typeof(double))
|
|
|
{
|
|
|
@@ -292,45 +290,6 @@ namespace WCS.Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 将字节转换成2进制的单精度浮点数
|
|
|
- /// </summary>
|
|
|
- /// <param name="ByteData"></param>
|
|
|
- /// <returns></returns>
|
|
|
- public float GetToTwo(byte[] ByteData)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- int Length = ByteData.Length;
|
|
|
- string Result = string.Empty;
|
|
|
- for (int j = 0; j < Length; j++)
|
|
|
- {
|
|
|
- string hexString = ByteData[j].ToString("X2");
|
|
|
- hexString = hexString.Replace(" ", "");
|
|
|
- if ((hexString.Length % 2) != 0)
|
|
|
- {
|
|
|
- hexString = hexString.PadRight(hexString.Length + 1);
|
|
|
- }
|
|
|
- StringBuilder builder = new StringBuilder();
|
|
|
- int len = hexString.Length / 2;
|
|
|
- for (int i = 0; i < len; i++)
|
|
|
- {
|
|
|
- string hex = hexString.Substring(i * 2, 2).Trim();
|
|
|
- int a = Convert.ToInt32(hex, 16);
|
|
|
- string str = Convert.ToString(a, 2).PadLeft(8, '0');
|
|
|
- builder = builder.Append(str);
|
|
|
- }
|
|
|
- Result += builder.ToString();
|
|
|
- }
|
|
|
- ;
|
|
|
- return Convert.ToInt32(Result, 2);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- throw new Exception("单精度浮点数转换失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private byte[] ReadBytes(ref int bitStart, ushort length)
|
|
|
{
|
|
|
var start = GetByteStart(bitStart);
|