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;


Continue reading...


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)

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

Continue reading...