static int nextPowerOfTwo(int val){
  int highestBit=Integer.highestOneBit(val);
  if (highestBit == val) {
    return val;
  }
 else {
    return highestBit << 1;
  }
}

static int nextPowerOfTwo ( int val ) { int highestBit = Integer . highestOneBit ( val ) ; if ( highestBit == val ) { return val ; } else { return highestBit << 1 ; } }
rounds up the provided value to the nearest power of two .
