Here given code implementation process.

``````/*
Java Program for
*/
{
public void addBinary(String a, String b)
{
String result = "";
// Get the length of given number
int x = a.length() - 1;
int y = b.length() - 1;
int sum = 0;

while (x >= 0 || y >= 0 || sum == 1)
{
if (x >= 0)
{
// Sum of binary digit at position x
sum += (a.charAt(x) - '0');
x--;
}
if (y >= 0)
{
// Sum of binary digit at position y
sum += (b.charAt(y) - '0');
y--;
}
result = (char)((sum % 2)+'0') + result;

sum = sum / 2;

}
// Display given value
System.out.println("Given a : " + a);
System.out.println("Given b : " + b);
System.out.println("Result  : " + result);
}
public static void main(String[] args)
{
// Test input
//   0101      5
//    111      7
// -----------------
//   1100      12
//   101011    43
//     1010    10
// ------------------
//   110101    53
//   1111      15
//   1111      15
// ------------------
//  11110      30
}
}``````

#### Output

``````Given a : 0101
Given b : 111
Result  : 1100
Given a : 101011
Given b : 1010
Result  : 110101
Given a : 1111
Given b : 1111
Result  : 11110``````
``````// Include header file
#include <iostream>
#include <string>

using namespace std;
/*
C++ Program for
*/
{
public: void addBinary(string a, string b)
{
string result = "";
// Get the length of given number
int x = a.length() - 1;
int y = b.length() - 1;
int sum = 0;
while (x >= 0 || y >= 0 || sum == 1)
{
if (x >= 0)
{
// Sum of binary digit at position x
sum += (a[x] - '0');
x--;
}
if (y >= 0)
{
// Sum of binary digit at position y
sum += (b[y] - '0');
y--;
}
result = ((char)((sum % 2) + '0'))  +  result;
sum = sum / 2;
}
// Display given value
cout << "Given a : " << a << endl;
cout << "Given b : " << b << endl;
cout << "Result  : " << result << endl;
}
};
int main()
{
// Test input
//   0101      5
//    111      7
// -----------------
//   1100      12
//   101011    43
//     1010    10
// ------------------
//   110101    53
//   1111      15
//   1111      15
// ------------------
//  11110      30
return 0;
}``````

#### Output

``````Given a : 0101
Given b : 111
Result  : 1100
Given a : 101011
Given b : 1010
Result  : 110101
Given a : 1111
Given b : 1111
Result  : 11110``````
``````// Include namespace system
using System;
/*
Csharp Program for
*/
{
public void addBinary(String a, String b)
{
String result = "";
// Get the length of given number
int x = a.Length - 1;
int y = b.Length - 1;
int sum = 0;
while (x >= 0 || y >= 0 || sum == 1)
{
if (x >= 0)
{
// Sum of binary digit at position x
sum += (a[x] - '0');
x--;
}
if (y >= 0)
{
// Sum of binary digit at position y
sum += (b[y] - '0');
y--;
}
result = (char)((sum % 2) + '0') + result;
sum = sum / 2;
}
// Display given value
Console.WriteLine("Given a : " + a);
Console.WriteLine("Given b : " + b);
Console.WriteLine("Result  : " + result);
}
public static void Main(String[] args)
{
// Test input
//   0101      5
//    111      7
// -----------------
//   1100      12
//   101011    43
//     1010    10
// ------------------
//   110101    53
//   1111      15
//   1111      15
// ------------------
//  11110      30
}
}``````

#### Output

``````Given a : 0101
Given b : 111
Result  : 1100
Given a : 101011
Given b : 1010
Result  : 110101
Given a : 1111
Given b : 1111
Result  : 11110``````
``````package main

import "fmt"
/*
Go Program for
*/

var result string = ""
// Get the length of given number
var x int = len(a) - 1
var y int = len(b) - 1
var sum int = 0
for (x >= 0 || y >= 0 || sum == 1) {
if x >= 0 {
// Sum of binary digit at position x
sum += (int(a[x]) - 48)
x--
}
if y >= 0 {
// Sum of binary digit at position y
sum += (int(b[y]) - 48)
y--
}
result = string(((sum % 2) + 48)) + result
sum = sum / 2
}
// Display given value
fmt.Println("Given a : ", a)
fmt.Println("Given b : ", b)
fmt.Println("Result  : ", result)
}
func main() {

// Test input
//   0101      5
//    111      7
// -----------------
//   1100      12
//   101011    43
//     1010    10
// ------------------
//   110101    53
//   1111      15
//   1111      15
// ------------------
//  11110      30
}``````

#### Output

``````Given a : 0101
Given b : 111
Result  : 1100
Given a : 101011
Given b : 1010
Result  : 110101
Given a : 1111
Given b : 1111
Result  : 11110``````
``````<?php
/*
Php Program for
*/
{
{
\$result = "";
// Get the length of given number
\$x = strlen(\$a) - 1;
\$y = strlen(\$b) - 1;
\$sum = 0;
while (\$x >= 0 || \$y >= 0 || \$sum == 1)
{
if (\$x >= 0)
{
// Sum of binary digit at position x
\$sum += (ord(\$a[\$x]) - ord('0'));
\$x--;
}
if (\$y >= 0)
{
// Sum of binary digit at position y
\$sum += (ord(\$b[\$y]) - ord('0'));
\$y--;
}
\$result = strval(chr(((\$sum % 2) + ord('0')))).\$result;
\$sum = (int)(\$sum / 2);
}
// Display given value
echo("Given a : ".\$a."\n");
echo("Given b : ".\$b."\n");
echo("Result  : ".\$result."\n");
}
}

function main()
{
// Test input
//   0101      5
//    111      7
// -----------------
//   1100      12
//   101011    43
//     1010    10
// ------------------
//   110101    53
//   1111      15
//   1111      15
// ------------------
//  11110      30
}
main();``````

#### Output

``````Given a : 0101
Given b : 111
Result  : 1100
Given a : 101011
Given b : 1010
Result  : 110101
Given a : 1111
Given b : 1111
Result  : 11110``````
``````/*
Node JS Program for
*/
{
{
var result = "";
// Get the length of given number
var x = a.length - 1;
var y = b.length - 1;
var sum = 0;
while (x >= 0 || y >= 0 || sum == 1)
{
if (x >= 0)
{
// Sum of binary digit at position x
sum += (a.charCodeAt(x) - '0'.charCodeAt(0));
x--;
}
if (y >= 0)
{
// Sum of binary digit at position y
sum += (b.charCodeAt(y) - '0'.charCodeAt(0));
y--;
}
result = String.fromCharCode(((sum % 2) + '0'.charCodeAt(0))) + result;
sum = parseInt(sum / 2);
}
// Display given value
console.log("Given a : " + a);
console.log("Given b : " + b);
console.log("Result  : " + result);
}
}

function main()
{
// Test input
//   0101      5
//    111      7
// -----------------
//   1100      12
//   101011    43
//     1010    10
// ------------------
//   110101    53
//   1111      15
//   1111      15
// ------------------
//  11110      30
}
main();``````

#### Output

``````Given a : 0101
Given b : 111
Result  : 1100
Given a : 101011
Given b : 1010
Result  : 110101
Given a : 1111
Given b : 1111
Result  : 11110``````
``````#    Python 3 Program for
result = ""
#  Get the length of given number
x = len(a) - 1
y = len(b) - 1
sum = 0
while (x >= 0 or y >= 0 or sum == 1) :
if (x >= 0) :
#  Sum of binary digit at position x
sum += (ord(a[x]) - ord('0'))
x -= 1

if (y >= 0) :
#  Sum of binary digit at position y
sum += (ord(b[y]) - ord('0'))
y -= 1

result = str(chr(((sum % 2) + ord('0')))) + result
sum = int(sum / 2)

#  Display given value
print("Given a : ", a)
print("Given b : ", b)
print("Result  : ", result)

def main() :
#  Test input
#    0101      5
#     111      7
#  -----------------
#    1100      12
#    101011    43
#      1010    10
#  ------------------
#    110101    53
#    1111      15
#    1111      15
#  ------------------
#   11110      30

if __name__ == "__main__": main()``````

#### Output

``````Given a :  0101
Given b :  111
Result  :  1100
Given a :  101011
Given b :  1010
Result  :  110101
Given a :  1111
Given b :  1111
Result  :  11110``````
``````#    Ruby Program for
result = ""
#  Get the length of given number
x = a.length - 1
y = b.length - 1
sum = 0
while (x >= 0 || y >= 0 || sum == 1)
if (x >= 0)
#  Sum of binary digit at position x
sum += (a[x].ord - '0'.ord)
x -= 1
end

if (y >= 0)
#  Sum of binary digit at position y
sum += (b[y].ord - '0'.ord)
y -= 1
end

result = (((sum % 2) + '0'.ord)).chr.to_s + result
sum = sum / 2
end

#  Display given value
print("Given a : ", a, "\n")
print("Given b : ", b, "\n")
print("Result  : ", result, "\n")
end

end

def main()
#  Test input
#    0101      5
#     111      7
#  -----------------
#    1100      12
#    101011    43
#      1010    10
#  ------------------
#    110101    53
#    1111      15
#    1111      15
#  ------------------
#   11110      30
end

main()``````

#### Output

``````Given a : 0101
Given b : 111
Result  : 1100
Given a : 101011
Given b : 1010
Result  : 110101
Given a : 1111
Given b : 1111
Result  : 11110
``````
``````/*
Scala Program for
*/
{
def addBinary(a: String, b: String): Unit = {
var result: String = "";
// Get the length of given number
var x: Int = a.length() - 1;
var y: Int = b.length() - 1;
var sum: Int = 0;
while (x >= 0 || y >= 0 || sum == 1)
{
if (x >= 0)
{
// Sum of binary digit at position x
sum += (a.charAt(x).toInt - '0'.toInt);
x -= 1;
}
if (y >= 0)
{
// Sum of binary digit at position y
sum += (b.charAt(y).toInt - '0'.toInt);
y -= 1;
}
result = ((sum % 2) + '0'.toInt).toChar.toString() + result;
sum = sum / 2;
}
// Display given value
println("Given a : " + a);
println("Given b : " + b);
println("Result  : " + result);
}
}
object Main
{
def main(args: Array[String]): Unit = {
// Test input
//   0101      5
//    111      7
// -----------------
//   1100      12
//   101011    43
//     1010    10
// ------------------
//   110101    53
//   1111      15
//   1111      15
// ------------------
//  11110      30
}
}``````

#### Output

``````Given a : 0101
Given b : 111
Result  : 1100
Given a : 101011
Given b : 1010
Result  : 110101
Given a : 1111
Given b : 1111
Result  : 11110``````
``````/*
Kotlin Program for
*/
{
fun addBinary(a: String, b: String): Unit
{
var result: String = "";
// Get the length of given number
var x: Int = a.length - 1;
var y: Int = b.length - 1;
var sum: Int = 0;
while (x >= 0 || y >= 0 || sum == 1)
{
if (x >= 0)
{
// Sum of binary digit at position x
sum += (a.get(x).toInt() - '0'.toInt());
x -= 1;
}
if (y >= 0)
{
// Sum of binary digit at position y
sum += (b.get(y).toInt() - '0'.toInt());
y -= 1;
}
result = ((sum % 2) + '0'.toInt()).toChar().toString() + result;
sum = sum / 2;
}
// Display given value
println("Given a : " + a);
println("Given b : " + b);
println("Result  : " + result);
}
}
fun main(args: Array < String > ): Unit
{
// Test input
//   0101      5
//    111      7
// -----------------
//   1100      12
//   101011    43
//     1010    10
// ------------------
//   110101    53
//   1111      15
//   1111      15
// ------------------
//  11110      30
}``````

#### Output

``````Given a : 0101
Given b : 111
Result  : 1100
Given a : 101011
Given b : 1010
Result  : 110101
Given a : 1111
Given b : 1111
Result  : 11110``````

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.