public static void Main()
Random rand = new Random();
for (int i = 0; i < n; i++)
f[i] = (byte)rand.Next(0, 256);
s[i] = (byte)rand.Next(0, 256);
byte[] result = AddRecursive(f, s);
result.Print("Total result");
public static byte[] AddRecursive(byte[] f, byte[] s)
return new byte[] { 1, (byte)(sum - 256) };
return new byte[] { 0, (byte)(sum) };
byte[] result = AddRecursive(f.Slice(1), s.Slice(1));
return new byte[] { 1, (byte)(sum - 256)}.Concat(result.Slice(1));;
return new byte[] { 0, (byte)(sum)}.Concat(result.Slice(1));
public static class ArrayExtensions
public static byte[] Slice(this byte[] array, int startIndex)
if (startIndex > array.Length)
throw new ArgumentException("Invalid startIndex");
byte[] result = new byte[array.Length - startIndex];
Array.Copy(array, startIndex, result, 0, result.Length);
public static byte[] Concat(this byte[] first, byte[] second)
byte[] result = new byte[first.Length + second.Length];
second.CopyTo(result, first.Length);
public static void Print(this byte[] array, string arrayName)
Console.WriteLine(arrayName + ": [" + String.Join(", ", array) + "]");