Example:
Input 1 : "101" Input 2 : "1010" Output : "1111"
Integer
's built-in method to convert binary Strings
to Integer
and vice versa.
1. Check if the input binary Strings
are not null, convert them to int
by using Integer's
built-in method called parseInt
. i.e. input1 = Integer.parseInt(binaryInput1, 2)
.
2. Similarly convert the second input binary String
to integer
.
3. Add two integers
and then convert the sum
back to binary String
with the help of toBinaryString()
built-in function of Integer
class. i.e. result = Integer.toBinaryString(
;
4. Return the result
.
public static String binaryAddition(String binaryInput1, String binaryInput2) { }
C
Java
Python