Skip to content

Commit 3a0c06b

Browse files
committed
New Problem
New Problem
1 parent 9124543 commit 3a0c06b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
768 Bytes
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*Copyright (c) Jul 2, 2015 CareerMonk Publications and others.
2+
* E-Mail : info@careermonk.com
3+
* Creation Date : 2015-01-10 06:15:46
4+
* Last modification : 2006-05-31
5+
by : Narasimha Karumanchi
6+
* File Name : SwapOddEvenBits.java
7+
* Book Title : Data Structures And Algorithms Made In Java
8+
* Warranty : This software is provided "as is" without any
9+
* warranty; without even the implied warranty of
10+
* merchantability or fitness for a particular purpose.
11+
*
12+
*/
13+
14+
15+
package chapter21miscconcepts;
16+
17+
public class SwapOddEvenBits {
18+
19+
public int swap(int num){
20+
int mask1 = 0xAAAAAAAA;
21+
int mask2 = 0x55555555;
22+
return (num << 1 & mask1) | ( num >> 1 & mask2);
23+
}
24+
25+
public static void main(String args[]){
26+
SwapOddEvenBits soe = new SwapOddEvenBits();
27+
System.out.println(soe.swap(697));
28+
}
29+
}

0 commit comments

Comments
 (0)