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