```
public String addBinary(String a, String b) {
int carry = 0, i = a.length()-1, j = b.length()-1, x , y;
String sum = "";
while (i >=0 || j >=0 || carry != 0) {
x = i < 0 ? 0 : a.charAt(i--) - 48;
y = j < 0 ? 0 : b.charAt(j--) - 48;
sum = (x ^ y ^ carry) + sum;
carry = (x + y + carry) / 2;
}
return sum;
}
```