408N/A/*
553N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
408N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
408N/A *
408N/A * This code is free software; you can redistribute it and/or modify it
408N/A * under the terms of the GNU General Public License version 2 only, as
408N/A * published by the Free Software Foundation.
408N/A *
408N/A * This code is distributed in the hope that it will be useful, but WITHOUT
408N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
408N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
408N/A * version 2 for more details (a copy is included in the LICENSE file that
408N/A * accompanied this code).
408N/A *
408N/A * You should have received a copy of the GNU General Public License version
408N/A * 2 along with this work; if not, write to the Free Software Foundation,
408N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
408N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
408N/A */
408N/A
408N/A/*
408N/A * @test
408N/A * @bug 6860965
408N/A * @summary Project Coin: binary literals
408N/A */
408N/A
408N/Apublic class BinaryLiterals {
408N/A public static void main(String... args) throws Exception {
408N/A new BinaryLiterals().run();
408N/A }
408N/A
408N/A public void run() throws Exception {
408N/A test(0, 0B0);
408N/A test(1, 0B1);
408N/A test(2, 0B10);
408N/A test(3, 0B11);
408N/A
408N/A test(0, 0b0);
408N/A test(1, 0b1);
408N/A test(2, 0b10);
408N/A test(3, 0b11);
408N/A
408N/A test(-0, -0b0);
408N/A test(-1, -0b1);
408N/A test(-2, -0b10);
408N/A test(-3, -0b11);
408N/A
408N/A test(-1, 0b11111111111111111111111111111111);
408N/A test(-2, 0b11111111111111111111111111111110);
408N/A test(-3, 0b11111111111111111111111111111101);
408N/A
408N/A test( 1, -0b11111111111111111111111111111111);
408N/A test( 2, -0b11111111111111111111111111111110);
408N/A test( 3, -0b11111111111111111111111111111101);
408N/A
408N/A test(0, 0b00);
408N/A test(1, 0b001);
408N/A test(2, 0b00010);
408N/A test(3, 0b000011);
408N/A
408N/A // aaaabbbbccccddddeeeeffffgggghhhh
408N/A test( 0x10, 0b10000);
408N/A test( 0x100, 0b100000000);
408N/A test( 0x10000, 0b10000000000000000);
408N/A test(0x80000000, 0b10000000000000000000000000000000);
408N/A test(0xffffffff, 0b11111111111111111111111111111111);
408N/A
408N/A test(0L, 0b0L);
408N/A test(1L, 0b1L);
408N/A test(2L, 0b10L);
408N/A test(3L, 0b11L);
408N/A
408N/A test(0, 0b00L);
408N/A test(1, 0b001L);
408N/A test(2, 0b00010L);
408N/A test(3, 0b000011L);
408N/A
408N/A // aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp
408N/A test( 0x10L, 0b10000L);
408N/A test( 0x100L, 0b100000000L);
408N/A test( 0x10000L, 0b10000000000000000L);
408N/A test( 0x80000000L, 0b10000000000000000000000000000000L);
408N/A test( 0xffffffffL, 0b11111111111111111111111111111111L);
408N/A test(0x8000000000000000L, 0b1000000000000000000000000000000000000000000000000000000000000000L);
408N/A test(0xffffffffffffffffL, 0b1111111111111111111111111111111111111111111111111111111111111111L);
408N/A
408N/A test(0l, 0b0l);
408N/A test(1l, 0b1l);
408N/A test(2l, 0b10l);
408N/A test(3l, 0b11l);
408N/A
408N/A test(0, 0b00l);
408N/A test(1, 0b001l);
408N/A test(2, 0b00010l);
408N/A test(3, 0b000011l);
408N/A
408N/A // aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp
408N/A test( 0x10l, 0b10000l);
408N/A test( 0x100l, 0b100000000l);
408N/A test( 0x10000l, 0b10000000000000000l);
408N/A test( 0x80000000l, 0b10000000000000000000000000000000l);
408N/A test( 0xffffffffl, 0b11111111111111111111111111111111l);
408N/A test(0x8000000000000000l, 0b1000000000000000000000000000000000000000000000000000000000000000l);
408N/A test(0xffffffffffffffffl, 0b1111111111111111111111111111111111111111111111111111111111111111l);
408N/A
408N/A if (errors > 0)
408N/A throw new Exception(errors + " errors found");
408N/A }
408N/A
408N/A void test(int expect, int found) {
408N/A count++;
408N/A if (found != expect)
408N/A error("test " + count + "\nexpected: 0x" + Integer.toHexString(expect) + "\n found: 0x" + Integer.toHexString(found));
408N/A }
408N/A
408N/A void test(long expect, long found) {
408N/A count++;
408N/A if (found != expect)
408N/A error("test " + count + "\nexpected: 0x" + Long.toHexString(expect) + "\n found: 0x" + Long.toHexString(found));
408N/A }
408N/A
408N/A void error(String message) {
408N/A System.out.println(message);
408N/A errors++;
408N/A }
408N/A
408N/A int count;
408N/A int errors;
408N/A}