9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 4495754
27 * @summary Basic test for int bit twiddling
28 * @author Josh Bloch
29 */
30
31 import java.util.Random;
32 import static java.lang.Integer.*;
33
34 public class BitTwiddle {
35 private static final int N = 1000; // # of repetitions per test
36
37 public static void main(String args[]) {
38 Random rnd = new Random();
39
40 if (highestOneBit(0) != 0)
41 throw new RuntimeException("a");
42 if (highestOneBit(-1) != MIN_VALUE)
43 throw new RuntimeException("b");
44 if (highestOneBit(1) != 1)
45 throw new RuntimeException("c");
46
47 if (lowestOneBit(0) != 0)
48 throw new RuntimeException("d");
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 4495754
27 * @summary Basic test for int bit twiddling
28 * @author Josh Bloch
29 * @key randomness
30 */
31
32 import java.util.Random;
33 import static java.lang.Integer.*;
34
35 public class BitTwiddle {
36 private static final int N = 1000; // # of repetitions per test
37
38 public static void main(String args[]) {
39 Random rnd = new Random();
40
41 if (highestOneBit(0) != 0)
42 throw new RuntimeException("a");
43 if (highestOneBit(-1) != MIN_VALUE)
44 throw new RuntimeException("b");
45 if (highestOneBit(1) != 1)
46 throw new RuntimeException("c");
47
48 if (lowestOneBit(0) != 0)
49 throw new RuntimeException("d");
|