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

Commit 45a766b

Browse files
author
Ram swaroop
committed
added comments
1 parent 700b651 commit 45a766b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/me/ramswaroop/bits/Modulo.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
*/
1010
public class Modulo {
1111

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+
*/
1220
public static int getNmoduloD(int n, int d) {
1321
return n & (d - 1);
1422
}
@@ -24,9 +32,9 @@ public static void main(String a[]) {
2432
}
2533

2634
/**
27-
* For example,
35+
* Consider example, for 18 % 8
2836
*
2937
* 18 = 10010
30-
* 8 = 01000
38+
* 7 = 00111 (8 = 2 ^ 3, therefore mask has to have three 1's)
3139
* 2 = 00010 (remainder = 18 & (8-1))
3240
*/

0 commit comments

Comments
 (0)