Skip to content

Commit 3b636e5

Browse files
Added Ones & Twos Complement
1 parent 1044d0c commit 3b636e5

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/main/java/com/thealgorithms/bitmanipulation/OnesComplement.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
/**
44
* @author - https://github.com/Monk-AbhinayVerma
55
* @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
77
* the complemented binary string.
88
* @return the complimented binary string
99
*/
1010
public class OnesComplement {
1111
// Function to get the 1's complement of a binary number
1212
public static String onesComplement(String binary) {
13-
StringBuilder complement = new StringBuilder();
13+
StringBuilder complement = new StringBuilder();
1414
// Invert each bit to get the 1's complement
1515
for (int i = 0; i < binary.length(); i++) {
1616
if (binary.charAt(i) == '0') {
@@ -21,6 +21,5 @@ public static String onesComplement(String binary) {
2121
}
2222
return complement.toString();
2323
}
24-
2524
}
2625

src/main/java/com/thealgorithms/bitmanipulation/TwosComplement.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @wikipedia - https://en.wikipedia.org/wiki/Two%27s_complement
44
* This Algorithm was first suggested by Jon Von Neumann
55
* @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
77
*/
88
public class TwosComplement {
99
// Function to get the 2's complement of a binary number
@@ -34,4 +34,4 @@ public static String twosComplement(String binary) {
3434
}
3535
return twosComplement.toString();
3636
}
37-
}
37+
}

0 commit comments

Comments
 (0)