Add two binary numbers with out using addition operator

PHOTO EMBED

Fri Apr 05 2024 15:35:35 GMT+0000 (Coordinated Universal Time)

Saved by @hiimsa #java

public String addBinary(String a, String b) {
       BigInteger num1 = new BigInteger(a,2);
       BigInteger num2 = new BigInteger(b,2);
       BigInteger zero = new BigInteger("0",2);
       BigInteger carry, answer;
       while(!num2.equals(zero)) {
        answer = num1.xor(num2);
        carry = num1.and(num2).shiftLeft(1);
        num1 = answer;
        num2 = carry;
       }
        return num1.toString(2);
    }
content_copyCOPY