Java Number Power power(int i)

Here you can find the source of power(int i)

Description

Calculates 2 to the power i as a helper in determining timings for some of the operations.

License

LGPL

Parameter

Parameter Description
i Power to which 2 is raised

Return

2 to the power i

Declaration

protected static int power(int i) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**//w w  w. j  a va  2  s  .  co m
     * Calculates 2 to the power i as a helper in determining timings
     * for some of the operations.
     * @param i Power to which 2 is raised   
     * @return  2 to the power i
     */
    protected static int power(int i) {
        if (i <= 0) {
            return 1;
        } else if (i == 1) {
            return 2;
        } else if (i == 2) {
            return 4;
        } else if (i > 32) {
            return Integer.MAX_VALUE;
        } else {
            int working = 2;
            for (int i2 = 1; i2 < i; i2++) {
                working = working * 2;
            }
            return working;
        }
    }
}

Related

  1. pow9(final double x)
  2. powDecay(double x, double y)
  3. power(double d, int exp)
  4. power(final long x, final long n, final long p)
  5. power(int base, int power)
  6. power(int val, int numOfPower)
  7. power(int x, int n)
  8. power(long x, long y)
  9. power2(int power)