### Question:
BitUtil { public static int nearbyPowerOfTwo(int x) { int next = nextHighestPowerOfTwo(x); int prev = next >>> 1; return (next - x) <= (x - prev) ? next : prev; } private  BitUtil(); static boolean isPowerOfTwo(final int value); static boolean isPowerOfTwo(final long value); static int previousPowerOfTwo(int v); static long previousPowerOfTwo(long v); static int nearbyPowerOfTwo(int x); static long nearbyPowerOfTwo(long x); static int nextHighestPowerOfTwo(int v); static long nextHighestPowerOfTwo(long v); static long align(long value, int alignment); static long ceilDiv(long dividend, long divisor); static int ceilDiv(int dividend, int divisor);  }### Answer:
@Test void shouldReturnNearbyPowerOfTwoForInts() { assertEquals(Integer.MIN_VALUE, nearbyPowerOfTwo(Integer.MIN_VALUE)); assertEquals(0, nearbyPowerOfTwo(Integer.MIN_VALUE + 1)); assertEquals(0, nearbyPowerOfTwo(-1)); assertEquals(0, nearbyPowerOfTwo(0)); assertEquals(1, nearbyPowerOfTwo(1)); assertEquals(2, nearbyPowerOfTwo(2)); assertEquals(4, nearbyPowerOfTwo(3)); assertEquals(4, nearbyPowerOfTwo(4)); assertEquals(4, nearbyPowerOfTwo(5)); assertEquals(8, nearbyPowerOfTwo(6)); assertEquals(8, nearbyPowerOfTwo(7)); assertEquals(8, nearbyPowerOfTwo(8)); assertEquals(32, nearbyPowerOfTwo(31)); assertEquals(32, nearbyPowerOfTwo(32)); assertEquals(32, nearbyPowerOfTwo(33)); assertEquals(1 << 30, nearbyPowerOfTwo(1 << 30)); assertEquals(1 << 30, nearbyPowerOfTwo((1 << 30) + 1)); assertEquals(Integer.MIN_VALUE, nearbyPowerOfTwo(Integer.MAX_VALUE - 1)); assertEquals(Integer.MIN_VALUE, nearbyPowerOfTwo(Integer.MAX_VALUE)); }
@Test void shouldReturnNearbyPowerOfTwoForLongs() { assertEquals(Long.MIN_VALUE, nearbyPowerOfTwo(Long.MIN_VALUE)); assertEquals(0L, nearbyPowerOfTwo(Long.MIN_VALUE + 1)); assertEquals(0L, nearbyPowerOfTwo(-1L)); assertEquals(0L, nearbyPowerOfTwo(0L)); assertEquals(1L, nearbyPowerOfTwo(1L)); assertEquals(2L, nearbyPowerOfTwo(2L)); assertEquals(4L, nearbyPowerOfTwo(3L)); assertEquals(4L, nearbyPowerOfTwo(4L)); assertEquals(4L, nearbyPowerOfTwo(5L)); assertEquals(8L, nearbyPowerOfTwo(6L)); assertEquals(8L, nearbyPowerOfTwo(7L)); assertEquals(8L, nearbyPowerOfTwo(8L)); assertEquals(32L, nearbyPowerOfTwo(31L)); assertEquals(32L, nearbyPowerOfTwo(32L)); assertEquals(32L, nearbyPowerOfTwo(33L)); assertEquals(1L << 62, nearbyPowerOfTwo(1L << 62)); assertEquals(1L << 62, nearbyPowerOfTwo((1L << 62) + 1)); assertEquals(Long.MIN_VALUE, nearbyPowerOfTwo(Long.MAX_VALUE - 1)); assertEquals(Long.MIN_VALUE, nearbyPowerOfTwo(Long.MAX_VALUE)); }