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 700b651 commit 45a766bCopy full SHA for 45a766b
src/me/ramswaroop/bits/Modulo.java
@@ -9,6 +9,14 @@
9
*/
10
public class Modulo {
11
12
+ /**
13
+ * Returns {@param n} modulo {@param d} provided
14
+ * {@param d} is a power of 2.
15
+ *
16
+ * @param n
17
+ * @param d
18
+ * @return
19
+ */
20
public static int getNmoduloD(int n, int d) {
21
return n & (d - 1);
22
}
@@ -24,9 +32,9 @@ public static void main(String a[]) {
24
32
25
33
26
34
/**
27
- * For example,
35
+ * Consider example, for 18 % 8
28
36
*
29
37
* 18 = 10010
30
- * 8 = 01000
38
+ * 7 = 00111 (8 = 2 ^ 3, therefore mask has to have three 1's)
31
39
* 2 = 00010 (remainder = 18 & (8-1))
40
0 commit comments