-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitPositions.java
More file actions
94 lines (71 loc) · 1.77 KB
/
Copy pathBitPositions.java
File metadata and controls
94 lines (71 loc) · 1.77 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
*Given a number n and two integers p1,p2 determine if the bits in position p1 and p2
*are the same or not. Positions p1,p2 and 1 based.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class position {
public static void main(String[] args) {
read(args[0]);
}
public static void read(String f) {
File file = new File(f);
try {
Scanner in = new Scanner(file);
while (in.hasNextLine()) {
dec(in.nextLine());
}
} catch (FileNotFoundException e) {
}
}
private static void dec(String s) {
Scanner sc = new Scanner(s);
sc.useDelimiter(",");
long a = sc.nextLong();
int b = sc.nextInt();
int c = sc.nextInt();
dec(a, b, c, s);
}
private static void dec(long a2, int b2, int c2, String s) {
String test = Long.toBinaryString(a2);
if (test.charAt(test.length() - b2) == test.charAt(test.length() - c2)) {
System.out.println(true);
}
else
System.out.println(false);
}
}import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class position {
public static void main(String[] args) {
read(args[0]);
}
public static void read(String f) {
File file = new File(f);
try {
Scanner in = new Scanner(file);
while (in.hasNextLine()) {
dec(in.nextLine());
}
} catch (FileNotFoundException e) {
}
}
private static void dec(String s) {
Scanner sc = new Scanner(s);
sc.useDelimiter(",");
long a = sc.nextLong();
int b = sc.nextInt();
int c = sc.nextInt();
dec(a, b, c, s);
}
private static void dec(long a2, int b2, int c2, String s) {
String test = Long.toBinaryString(a2);
if (test.charAt(test.length() - b2) == test.charAt(test.length() - c2)) {
System.out.println(true);
}
else
System.out.println(false);
}
}