1

I am receiving an array of bytes periodically, of irregular size. What i am looking for is a specific size, since each received message has a consistent size of 27 bytes. It looks something like this:

"0 2 0 ....... XX 0"

so sometimes the received array will look like this "0 0 2 .... "

I can use the BinarySearch function in http://msdn.microsoft.com/en-us/library/aa310858(v=vs.71).aspx

to help me identify the index of the first zero i find, then check if the next byte is 2. However, if that's not the case, i move on to the next index, and continue checking and so on. But it seems to me like this isn't a good way, and is going to lead to some messy code. Does anybody have a better idea to help me identify the start of a read byte?

2
  • A binary search will only work on a sorted array. It doesn't sound like you have a sorted array, so BinarySearch will not work for you. That said, I don't understand what your task is. Are you just searching a byte array for 0 followed by 2? Commented Nov 26, 2014 at 4:04
  • ya, just realized binarysearch does not work for me. i wanted to search for the index in the array where 2 follows after a 0. Commented Nov 26, 2014 at 4:36

1 Answer 1

1

Since it's an array of bytes, it would be easy to scan the array with a for loop.

for i as integer = 0 to ubound(bytearray)-1
  if bytearray(i) = 0 andalso bytearray(i+1) = 2 then ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.