Iv'e been trying to subtract the value of a byte array from another byte array, which values i read from a file. I tried to convert the arrays to integers and then subtract the value finally restoring back to byte array.
The problem is that i need to get the value from another byte array and use that to subtract from another byte array.
I have the following code,
byte[] arr_i = {0x01,0x02,0x03};
byte[] arr_j = {0x04,0x05,0x06};
int i = BitConverter.ToInt32(arr_i, 0);
int j = BitConverter.ToInt32(arr_j, 0);
int sub = j - i;
byte[] sum = BitConverter.GetBytes(sub);
Once i get to the i variable i get the error
{"Destination array is not long enough to copy all the items in the collection. Check array index and length."}
Which seems to me that theres some sort of mismatch between the types, but i didnt find any example of doing this without it.
Thanks
BitConverter.ToInt32doesn't convert frombytetoint- it reads four bytes from thebyte[]you passed and interprets them as an integer. Since your array only has three bytes, this will cause an exception. But to help you fix the problem, we need to see a good example of what you're trying to do.