Skip to content

Commit fe28d02

Browse files
committed
check if a number is odd or even bitwise
1 parent 5393038 commit fe28d02

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
- [x] Hamming Weight implementation (return 1-bits of a binary representation of a number)
5454
- [x] [Binary to Decimal Converter](https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-3-binary-to-decimal-converter/)
5555
- [x] [Reverse bits](https://leetcode.com/problems/reverse-bits/)
56+
- [x] [Bit Hacks — Part 1 (Basic)](http://www.techiedelight.com/bit-hacks-part-1-basic/)
57+
5658

5759
## Algorithms
5860

@@ -170,7 +172,6 @@
170172
## To Do
171173

172174
- Bits Manipulation
173-
- [ ] [Bit Hacks — Part 1 (Basic)](http://www.techiedelight.com/bit-hacks-part-1-basic/)
174175
- [ ] [Bit Hacks — Part 2 (Playing with k’th bit)](http://www.techiedelight.com/bit-hacks-part-2-playing-kth-bit/)
175176
- [ ] [Bit Hacks — Part 3 (Playing with rightmost set bit of a number)](http://www.techiedelight.com/bit-hacks-part-3-playing-rightmost-set-bit-number/)
176177
- [ ] [Bit Hacks — Part 4 (Playing with letters of English alphabet)](http://www.techiedelight.com/bit-hacks-part-4-playing-letters-english-alphabet/)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package binary.binCheckOddOrEven;
2+
3+
import utils.InputReader;
4+
5+
// The expression n & 1 returns value 1 or 0 depending upon whether n is odd or even.
6+
public class BinaryCheckOddEvenNum {
7+
public static void main(String[] args) {
8+
System.out.print("Input a number: ");
9+
int n = InputReader.readInt();
10+
if ((n & 1) != 0) {
11+
System.out.println(n + " is odd");
12+
}
13+
else {
14+
System.out.println(n + " is even");
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)