ALGORITHMS

Bitwise GCD:

Bitwise GCD is applicable only for unsigned int. It's 60% faster than normal numeric gcd algorithm. The quick short implementation of bitwise GCD is:

public int gcd(int a, int b) {
    while(b) b ^= a ^= b ^= a % b;
    return a;
}

Ref: https://en.wikipedia.org/wiki/Binary_GCD_a...

Continue reading...

ALL_BITS:

Getting an integer with all bits set. Following expression will provide us an integer of 31 bits where all bits set. Maximum positive integer of **int** data type.

(1 << 31) - 1

#define ALL_BITS                 ((1 << 31) - 1)
NEG_BITS:

Given an integer N, generate a new intege...

Continue reading...