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 f78ff8d commit f7df381Copy full SHA for f7df381
src/me/ramswaroop/bits/Modulo.java
@@ -0,0 +1,32 @@
1
+package me.ramswaroop.bits;
2
+
3
+/**
4
+ * Created by IntelliJ IDEA.
5
+ *
6
+ * @author: ramswaroop
7
+ * @date: 6/8/15
8
+ * @time: 11:28 PM
9
+ */
10
+public class Modulo {
11
12
+ public static int getNmoduloD(int n, int d) {
13
+ return n & (d - 1);
14
+ }
15
16
+ public static void main(String a[]) {
17
+ System.out.println(getNmoduloD(18, 8));
18
+ System.out.println(getNmoduloD(18, 4));
19
+ System.out.println(getNmoduloD(13, 4));
20
+ System.out.println(getNmoduloD(13, 1));
21
+ System.out.println(getNmoduloD(2, 2));
22
+ System.out.println(getNmoduloD(13, 16));
23
24
+}
25
26
27
+ * For example,
28
29
+ * 18 = 10010
30
+ * 8 = 01000
31
+ * 2 = 00010 (remainder = 18 & (8-1))
32
0 commit comments