I'm trying to write a method in C# that will return the difference between two byte arrays by comparing each byte in the arrays and returning the byte from the second if it is different from the first. I have this so far:
byte[] b1 = 111;
byte[] b2 = 105;
int j = input.Length;
byte[] differenceByte = new byte[j];
int diffIndex = 0;
for (int i = 0; i < j; i++)
{
if (originalByte[i] != comparisonByte[i])
differenceByte[diffIndex++] = comparisonByte[i];
}
But I was hoping to find a way to replace the if statement comparing the first byte to the second with some bitwise voodoo magic... Is there a way to do this?
A second question is there any other way to optimize this code so that it will run as fast as possible?
I would ultimately like to use this code to compare two strings by converting the strings to and from an array of bytes, so if there is something I should know about in that respect, that would also be helpful.