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

Commit 91e45f3

Browse files
author
Ram swaroop
committed
sub bit number problem done
1 parent 39aa7a3 commit 91e45f3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/me/ramswaroop/bits/SubBit.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package me.ramswaroop.bits;
2+
3+
/**
4+
* Created by IntelliJ IDEA.
5+
*
6+
* @author: ramswaroop
7+
* @date: 6/4/15
8+
* @time: 10:54 PM
9+
*/
10+
public class SubBit {
11+
12+
/**
13+
* Returns the number formed with the bits from {@param start}
14+
* and {@param end} of {@param num} (both inclusive).
15+
*
16+
* @param num
17+
* @param start
18+
* @param end
19+
* @return
20+
*/
21+
public static int getSubBit(int num, int start, int end) {
22+
num <<= (32 - end);
23+
num >>>= (start - end + 31);
24+
return num;
25+
}
26+
27+
public static void main(String a[]) {
28+
System.out.println(getSubBit(15, 1, 2));
29+
}
30+
}

0 commit comments

Comments
 (0)