Skip to content

Commit 9e40b8c

Browse files
committed
added bitmasking
1 parent 132fbee commit 9e40b8c

File tree

6 files changed

+33
-40
lines changed

6 files changed

+33
-40
lines changed

.idea/workspace.xml

Lines changed: 16 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/com/company/Lecture7/Bitwise_Examples.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.company.Lecture7;
22

3-
//import javafx.scene.transform.Scale;
4-
53
import java.lang.reflect.Array;
64
import java.util.Arrays;
75
import java.util.Scanner;
@@ -10,24 +8,23 @@ public class Bitwise_Examples {
108
public static void main(String[] args) {
119
Scanner s = new Scanner(System.in);
1210

13-
// String[] any = s.nextLine().trim().split(" ");
14-
// int[] nums = new int[any.length];
15-
// for (int i = 0; i < any.length ; i++) {
16-
// nums[i] = Integer.parseInt(any[i]);
17-
// }
18-
// System.out.println(Arrays.toString(nums));
19-
// System.out.println(5 & 11);
20-
// System.out.println(5 | 11);
11+
String[] any = s.nextLine().trim().split(" ");
12+
int[] nums = new int[any.length];
13+
for (int i = 0; i < any.length ; i++) {
14+
nums[i] = Integer.parseInt(any[i]);
15+
}
16+
System.out.println(Arrays.toString(nums));
17+
System.out.println(5 & 11);
18+
System.out.println(5 | 11);
19+
20+
int[] num2 = {2,1,8,1,8,2};
21+
int res = oddOcc(num2);
22+
System.out.println(res);
2123

22-
// int[] num2 = {2,1,8,1,8,2};
23-
// int res = oddOcc(num2);
24-
// System.out.println(res);
25-
//
26-
// System.out.println(countOne(15));
27-
// toggle_basic(14);
28-
// toggle(14);
24+
System.out.println(countOne(15));
25+
toggle_basic(14);
26+
toggle(14);
2927
System.out.println(power(3,2));
30-
3128
}
3229

3330
public static int oddOcc(int[] nums){
@@ -39,7 +36,7 @@ public static int oddOcc(int[] nums){
3936
}
4037

4138
public static boolean isOdd( int n){
42-
return (n & 1) == 0;
39+
return (n & 1) == 1;
4340
//If returns 1 : odd else even.
4441
}
4542

@@ -59,7 +56,7 @@ public static void toggle_basic (int n){
5956
int num = 0,place=1;
6057
while(n>0){
6158
if((n & 1)==0){
62-
num = num + 1*place;
59+
num = num + place;
6360
}
6461
place *= 2;
6562
n = n >> 1;

0 commit comments

Comments
 (0)