-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalClass.java
More file actions
33 lines (32 loc) · 1.04 KB
/
Copy pathLocalClass.java
File metadata and controls
33 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class LocalClass {
public static void main(String[] args) {
// An inner class version of ShowBits - not available outside
class ShowBits {
int numbits;
ShowBits(int n) {
numbits = n;
}
void show(long val) {
long mask = 1;
// Left-shift a 1 into the proper position.
mask <<= numbits-1;
int spacer = 0;
for (; mask != 0; mask >>>= 1) {
if ((val & mask) != 0) System.out.print("1");
else System.out.print("0");
spacer++;
if ((spacer % 8) == 0) {
System.out.print(" ");
spacer = 0;
}
}
System.out.println();
}
}
for (byte b = 0; b < 10; b++) {
ShowBits byteval = new ShowBits(8);
System.out.print(b + " in binary: ");
byteval.show(b);
}
}
}