We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 39aa7a3 commit 91e45f3Copy full SHA for 91e45f3
src/me/ramswaroop/bits/SubBit.java
@@ -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