Here you can find the source of power(int i)
Parameter | Description |
---|---|
i | Power to which 2 is raised |
protected static int power(int i)
//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; } } }