File tree 2 files changed +4
-5
lines changed
src/main/java/com/thealgorithms/bitmanipulation
2 files changed +4
-5
lines changed Original file line number Diff line number Diff line change 3
3
/**
4
4
* @author - https://github.com/Monk-AbhinayVerma
5
5
* @Wikipedia - https://en.wikipedia.org/wiki/Ones%27_complement
6
- * The class OnesComplement computes the complement of binary number and returns
6
+ * The class OnesComplement computes the complement of binary number and returns
7
7
* the complemented binary string.
8
8
* @return the complimented binary string
9
9
*/
10
10
public class OnesComplement {
11
11
// Function to get the 1's complement of a binary number
12
12
public static String onesComplement (String binary ) {
13
- StringBuilder complement = new StringBuilder ();
13
+ StringBuilder complement = new StringBuilder ();
14
14
// Invert each bit to get the 1's complement
15
15
for (int i = 0 ; i < binary .length (); i ++) {
16
16
if (binary .charAt (i ) == '0' ) {
@@ -21,6 +21,5 @@ public static String onesComplement(String binary) {
21
21
}
22
22
return complement .toString ();
23
23
}
24
-
25
24
}
26
25
Original file line number Diff line number Diff line change 3
3
* @wikipedia - https://en.wikipedia.org/wiki/Two%27s_complement
4
4
* This Algorithm was first suggested by Jon Von Neumann
5
5
* @author - https://github.com/Monk-AbhinayVerma
6
- * @return the two's complement of any binary number
6
+ * @return the two's complement of any binary number
7
7
*/
8
8
public class TwosComplement {
9
9
// Function to get the 2's complement of a binary number
@@ -34,4 +34,4 @@ public static String twosComplement(String binary) {
34
34
}
35
35
return twosComplement .toString ();
36
36
}
37
- }
37
+ }
You can’t perform that action at this time.
0 commit comments