Hey there,
I've got a buffer with byte[] data I'd like to process the data in this buffer in the most efficient way possible. Because the byte[] contains several numbers in ascii form I think it makes more sense to copy the bytes out into another byte array and convert that instead of converting the whole buffer into a string and using sub strings for the values. But I could be wrong so if I could get some advice or pointers on these things below that would be great, thanks.
// byte[] copy function, I think there might be a .NET equivalent but I’m not sure
byte[] byteCopy(byte[] bytes, int begin, int end) {
int size = end - begin;
byte[] value = new byte[size];
for (int i = 0; i < size; i++) {
value = bytes[begin + i];
}
return value;
}
// converting from byte[] ascii data into an integer value.
byte[] buffer[] = new byte[1024];
...
byte[] number = byteCopy(buffer, 0, 2);
int station = Int32.Parse(ASCIIEncoding.UTF8.GetString(number));
try {
station = Int32.Parse(ASCIIEncoding.UTF8.GetString(number));
} catch (Exception e) {
pannel.UpdateLog("Invalid Data.");
}