public double powerUsingBit(double x, int n) {
        if (n == 0) {
            return 1;
        }
        long r = n;
        if (r < 0) {
            x = 1/x;
            r = -r;
        }
        double power = x;
        double result = x;
        double result1 = 1;
        while (r > 1) {
            result *= result;
            if ((r & 1) != 0) {
                result1 = result1 * power;
            }
            r = r >> 1;
            power = power * power;
        }
        return result * result1;
    }
Date 03/13/2016
@author Tushar Roy

Find power of 2 numbers.

Time complexity O(logn)
Space complexity O(1)

https://leetcode.com/problems/powx-n/
http://www.geeksforgeeks.org/write-a-c-program-to-calculate-powxn/
src/com/interview/number/PowerFunction.java