Created method to get int from data (not quite safe yet)

This commit is contained in:
Roar Fredriksen
2017-09-19 23:50:49 +02:00
parent 8df007689d
commit 7f604e3594
2 changed files with 39 additions and 0 deletions

View File

@@ -43,5 +43,28 @@ namespace HanDebugger
return new DateTime(year, month, day, hour, minute, second).Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
}
public static int GetInt(int dataPosition, byte[] buffer, int start, int length)
{
const int dataStart = 24;
int value = 0;
int foundPosition = 0;
for (int i = start + dataStart; i < start + length; i++)
{
if (foundPosition == 0)
{
if (buffer[i] == 0x06)
foundPosition = i;
}
else
{
value = value << 8 |
buffer[i];
if (i == foundPosition + 4)
return value;
}
}
return 0;
}
}
}