Here's a Naive code sample to explain what I'm suggesting in my comments (I'm sure that there are better ways of encoding the logic but hopefully it gets the gist across)...
static public byte[] AddBytes(byte[] a, byte[] b)
{
if (a.Length != b.Length)
{
throw new InvalidOperationException("Mismatched array lengths is not currently supported");
}
byte[] result = new byte[a.Length + 1];
int carry = 0;
for (int x = a.Length - 1; x >= 0; x--)
{
int tempresult = a[x] + b[x] + carry;
result[x + 1] =(byte)(tempresult);
carry = tempresult / (byte.MaxValue + 1);
}
if (carry > 0)
{
// Carried into extra byte, so return it
result[0] = (byte)carry;
return result;
}
// no carry into extra byte, so remove it
return result.Skip(1).ToArray();
}
static void Main(string[] args)
{
byte[] a = { 1, 1, 1 };
byte[] b = { 1, 1, 1 };
byte[] c = { 1, 1, 255 };
byte[] d = { 0, 0, 1 };
byte[] e = { 255, 255, 255 };
byte[] f = { 255, 255, 255 };
var x = AddBytes(a, b);
x = AddBytes(c, d);
x = AddBytes(e, f);
}
As I've said, this is essentially assuming that the byte array represents numbers...
So, {1,1,1} is equivalent to 0x10101 or 65793
65793 + 65793 = 131586 or 0x20202 i.e. {2,2,2}
and, {1,1,255} + {0,0,1} is equivalent to 0x101FF + 0x1 or 66047 + 1 = 66048 or 0x10200 i.e. {1,2,0}