Ha, I wouldn't grab your thought if I didn't come across your post in Quick Answer section. Please edit your post here so that other people would understand. Ok, first the function might have overflow issue, depending on the logic, and it is not exception safe, leading to unexpected results. But it's nothing to do with your question, so I will pass this part. I assume 1. TByteDynArray is array of Byte. if it's not, the following might be useless. :sigh: 2. and endian representation is the same on all machines where your codes will run.
double BufToDataBin(byte[] Buf, int iStartPos, int iLen, int iDec)
{
const int DefaultLen = 8;
double fTmp = 0;
Int64 iTmp = 0;
try
{
byte[] arr = { 0, 0, 0, 0, 0, 0, 0, 0 };
if ((Buf[iStartPos] & 0x80) == 0x80 && !IsCardinal)//IsCardinal??
{
if (Negative)//Negative??
{
for (int i = 0; i <= iLen - 2; ++i)
{
arr[i] = (byte)(Buf[iStartPos + iLen - 1 - i] ^ 0xFF);
}
iTmp = BitConverter.ToInt64(arr, 0);
}
else
{
for (int i = 0; i <= iLen - 2; ++i)
{
arr[i] = (byte)(Buf[iStartPos+iLen-1-i]);
}
iTmp = BitConverter.ToInt64(arr, 0);
}
fTmp = 0 - iTmp / Math.Pow(10, iDec);
}
else
{
for (int i = 0; i < iLen; ++i)
{
arr\[i\] = Buf\[iStartPos+iLen-1-i\];
}
iTmp = BitConverter.ToInt64(arr, 0);
fTmp = iTmp / Math.Pow(10, iDec);
}
}
catch
{
//do something
}
return fTmp;
}
Further optimization might be requested.