-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplaceBit.java
More file actions
30 lines (26 loc) · 929 Bytes
/
ReplaceBit.java
File metadata and controls
30 lines (26 loc) · 929 Bytes
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
/**
* Created by MalhotR1 on 04/19/2017.
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
public class ReplaceBit {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
for (int t = 0; t < T; t++) {
String[] in = br.readLine().trim().split(" ");
int n = Integer.parseInt(in[0]);
int k = Integer.parseInt(in[1]);
char[] arr = Integer.toBinaryString(n).toCharArray();
if (arr[k-1] == '1') arr[k-1] = '0';
n = 0;
int l = 0;
for (int i = arr.length - 1; i >= 0; i--, l++) {
n += (arr[i] - 48) * (int) Math.pow(2,l);
}
System.out.println(n);
}
}
}