// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class MainClass { public static string Add(string s1, string s2) { char[] res = new char[s1.Length]; int mente = 0; for(int i = res.Length - 1; i >= 0; i--) { int tmp = (s1[i] - '0') + (s2[i] - '0') + mente; res[i] = (char)('0' + tmp % 2); mente = tmp / 2; } return new string(res); } public static void Main(string[] args) { Console.WriteLine(Add("0000", "0000")); Console.WriteLine(Add("0001", "0000")); Console.WriteLine(Add("0000", "0001")); Console.WriteLine(Add("0001", "0001")); Console.WriteLine(Add("0010", "0000")); Console.WriteLine(Add("0010", "0001")); Console.WriteLine(Add("0010", "0010")); Console.WriteLine(Add("0010", "0011")); } } }