3895
|
1 |
/*
|
5520
|
2 |
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
3895
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
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 |
*
|
5520
|
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.
|
3895
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6860965
|
|
27 |
* @summary Project Coin: binary literals
|
|
28 |
*/
|
|
29 |
|
|
30 |
public class BinaryLiterals {
|
|
31 |
public static void main(String... args) throws Exception {
|
|
32 |
new BinaryLiterals().run();
|
|
33 |
}
|
|
34 |
|
|
35 |
public void run() throws Exception {
|
|
36 |
test(0, 0B0);
|
|
37 |
test(1, 0B1);
|
|
38 |
test(2, 0B10);
|
|
39 |
test(3, 0B11);
|
|
40 |
|
|
41 |
test(0, 0b0);
|
|
42 |
test(1, 0b1);
|
|
43 |
test(2, 0b10);
|
|
44 |
test(3, 0b11);
|
|
45 |
|
|
46 |
test(-0, -0b0);
|
|
47 |
test(-1, -0b1);
|
|
48 |
test(-2, -0b10);
|
|
49 |
test(-3, -0b11);
|
|
50 |
|
|
51 |
test(-1, 0b11111111111111111111111111111111);
|
|
52 |
test(-2, 0b11111111111111111111111111111110);
|
|
53 |
test(-3, 0b11111111111111111111111111111101);
|
|
54 |
|
|
55 |
test( 1, -0b11111111111111111111111111111111);
|
|
56 |
test( 2, -0b11111111111111111111111111111110);
|
|
57 |
test( 3, -0b11111111111111111111111111111101);
|
|
58 |
|
|
59 |
test(0, 0b00);
|
|
60 |
test(1, 0b001);
|
|
61 |
test(2, 0b00010);
|
|
62 |
test(3, 0b000011);
|
|
63 |
|
|
64 |
// aaaabbbbccccddddeeeeffffgggghhhh
|
|
65 |
test( 0x10, 0b10000);
|
|
66 |
test( 0x100, 0b100000000);
|
|
67 |
test( 0x10000, 0b10000000000000000);
|
|
68 |
test(0x80000000, 0b10000000000000000000000000000000);
|
|
69 |
test(0xffffffff, 0b11111111111111111111111111111111);
|
|
70 |
|
|
71 |
test(0L, 0b0L);
|
|
72 |
test(1L, 0b1L);
|
|
73 |
test(2L, 0b10L);
|
|
74 |
test(3L, 0b11L);
|
|
75 |
|
|
76 |
test(0, 0b00L);
|
|
77 |
test(1, 0b001L);
|
|
78 |
test(2, 0b00010L);
|
|
79 |
test(3, 0b000011L);
|
|
80 |
|
|
81 |
// aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp
|
|
82 |
test( 0x10L, 0b10000L);
|
|
83 |
test( 0x100L, 0b100000000L);
|
|
84 |
test( 0x10000L, 0b10000000000000000L);
|
|
85 |
test( 0x80000000L, 0b10000000000000000000000000000000L);
|
|
86 |
test( 0xffffffffL, 0b11111111111111111111111111111111L);
|
|
87 |
test(0x8000000000000000L, 0b1000000000000000000000000000000000000000000000000000000000000000L);
|
|
88 |
test(0xffffffffffffffffL, 0b1111111111111111111111111111111111111111111111111111111111111111L);
|
|
89 |
|
|
90 |
test(0l, 0b0l);
|
|
91 |
test(1l, 0b1l);
|
|
92 |
test(2l, 0b10l);
|
|
93 |
test(3l, 0b11l);
|
|
94 |
|
|
95 |
test(0, 0b00l);
|
|
96 |
test(1, 0b001l);
|
|
97 |
test(2, 0b00010l);
|
|
98 |
test(3, 0b000011l);
|
|
99 |
|
|
100 |
// aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp
|
|
101 |
test( 0x10l, 0b10000l);
|
|
102 |
test( 0x100l, 0b100000000l);
|
|
103 |
test( 0x10000l, 0b10000000000000000l);
|
|
104 |
test( 0x80000000l, 0b10000000000000000000000000000000l);
|
|
105 |
test( 0xffffffffl, 0b11111111111111111111111111111111l);
|
|
106 |
test(0x8000000000000000l, 0b1000000000000000000000000000000000000000000000000000000000000000l);
|
|
107 |
test(0xffffffffffffffffl, 0b1111111111111111111111111111111111111111111111111111111111111111l);
|
|
108 |
|
|
109 |
if (errors > 0)
|
|
110 |
throw new Exception(errors + " errors found");
|
|
111 |
}
|
|
112 |
|
|
113 |
void test(int expect, int found) {
|
|
114 |
count++;
|
|
115 |
if (found != expect)
|
|
116 |
error("test " + count + "\nexpected: 0x" + Integer.toHexString(expect) + "\n found: 0x" + Integer.toHexString(found));
|
|
117 |
}
|
|
118 |
|
|
119 |
void test(long expect, long found) {
|
|
120 |
count++;
|
|
121 |
if (found != expect)
|
|
122 |
error("test " + count + "\nexpected: 0x" + Long.toHexString(expect) + "\n found: 0x" + Long.toHexString(found));
|
|
123 |
}
|
|
124 |
|
|
125 |
void error(String message) {
|
|
126 |
System.out.println(message);
|
|
127 |
errors++;
|
|
128 |
}
|
|
129 |
|
|
130 |
int count;
|
|
131 |
int errors;
|
|
132 |
}
|