public static void Main()
for(int i = 1; i < 1000000; i++)
if(palindrome10(i) && palindrome2(i)){
Console.WriteLine("The sum of all numbers, less than one million, which are palindromic in base 10 and base 2, is {0}.", res);
public static bool palindrome10(int n)
int numDigits = (int)(Math.Log10(n)) + 1;
for(int i = 1; i <= numDigits / 2; i++)
if((int)(n / Math.Pow(10, numDigits - i) % 10) != (int)(n / Math.Pow(10, i - 1) % 10))
public static bool palindrome2(int n)
int numDigits = (int)(Math.Log(n, 2) + 1);
for(int i = 1; i <= numDigits / 2; i++)
if((int)(n / Math.Pow(2, numDigits - i) % 2) != (int)(n / Math.Pow(2, i - 1) % 2))