File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
bin/chapter21miscconcepts
src/chapter21miscconcepts Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments