Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ecd9475

Browse files
author
Ram swaroop
committed
code shortened/improved
1 parent 0977f08 commit ecd9475

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/me/ramswaroop/bits/SubBit.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ public class SubBit {
1919
* @return
2020
*/
2121
public static int getSubBits(int num, int start, int end) {
22-
num <<= (32 - end);
23-
num >>>= (start - end + 31); // more intuitive (start - 1 + 32 - end)
22+
num = num << (32 - end) >>> (start - end + 31); // more intuitive (start - 1 + 32 - end)
2423
return num;
2524
}
2625

2726
public static void main(String a[]) {
28-
System.out.println(getSubBits(15, 1, 2));
27+
System.out.println(getSubBits(5, 1, 2));
2928
}
3029
}

0 commit comments

Comments
 (0)