I have byte[1024] and I am parsing it for some structures moving
towards the end using index variable
so after I read the structure, I increment the index by its size. Then
I want to find out whether there are more structures by seeing if rest
of bits are 0 or not.
what is the standard way to do it?
Here is some code, tell me if this answers your question because I
can't really tell what your question is:
using System;
public static class EntryPoint {
static byte[] bytes;
public static void Main() {
bytes = new byte[1024];
FillABlock(ref bytes, 100); // put 100 bytes of junk in bytes[0]--
// bytes[99], leave bytes[100]--bytes[1023] empty
bool r1 = IsTheRestEmpty(bytes, 80); // returns false
bool r2 = IsTheRestEmpty(bytes, 100); // returns true
Console.WriteLine(r1); // False
Console.WriteLine(r2); // True
}
public static void FillABlock(ref byte[] buf, int size) {
if(size > buf.Length)
throw new ArgumentOutOfRangeException("size",
"Cannot be > buf.Length");
for(int i = 0; i < size; i++) {
buf
= (byte)(i % 256);
}
}
public static bool IsTheRestEmpty(byte[] buf, int startingFrom) {
for(int i = startingFrom; i < buf.Length; i++) {
if(buf != 0) return(false);
}
return(true);
}
}