I spent long time understanding how programmers use the advantage of speedy binary representation of data in C# arrays but I just dont get it.
for example If I have 2 arrays A, and B to store 0/1 data. In normal situation we do like this :
bool flag=true;
int[] A = new int[10] { 1, 0, 0, 0, 1, 1, 0, 1, 0, 0 };
int[] B = new int[10] { 1, 1, 1, 0, 0, 1, 0, 1, 0, 0 };
for(int i=0;i<5;i++)
if (A[i] != B[i])
{
flag = false;
break;
}
A[7]=1;
int x=B[5];
What if I need to repeat this code for thousands of times ? or even the arrays are very large ? the straight answer will be to represent the data as bit packed arrays and apply things like bitwise operations or bitmasking ... etc.
My question is how to switch to the binary world in c# ? for more accurate question, How to rewrite the code above in very efficient way using the binary representation and bit wise operations ? Answer with demo code will be much appreciated.