int sum(int a, int b) { int s = a ^ b; // partial sum int c = (a & b) << 1; // carry // carry? while( c != 0 ) { // yes -> sum it, recalc carry int newc = (s & c) << 1; s = s ^ c; c = newc; } return s; }
Other entries:
- isPrime: Naive version
- isPrime, Optimization 1: Iterate only until the square root of the number
- isPrime, Optimization 2: Only divide by odd numbers, until the square root of the number
- isPrime, Optimization 3: Skip the divisors that are multiple of 2 or 3
- Keep the previosly generated primes and use them to test the following numbers.
- isPrime, Recursive.