Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string binaryAddition(std::string a, std::string b) {
- std::string b1 = a;
- std::string b2 = b;
- std::string c;
- bool z = false;
- while (c.length() != a.length())
- {
- for (int i = 0; i < a.length(); i++)
- {
- std::cout << "A: " << b1[i] << ", " << "B: " << b2[i] << ", " << "Z: " << z << std::endl;
- if ((b1[i] == 1) && (b2[i] == 0) && (z == false))
- {
- c.push_back(1);
- z = false;
- }
- else if ((b1[i] == 0) && (b2[i] == 0) && (z == true))
- {
- c.push_back(1);
- z = false;
- }
- else if ((b1[i] == 0) && (b2[i] == 0) && (z == false))
- {
- c.push_back(0);
- z = false;
- }
- else if ((b1[i] == 1) && (b2[i] == 1) && (z == false))
- {
- c.push_back(0);
- z = true;
- }
- else if ((b1[i] == 1) && (b2[i] == 0) && (z == true))
- {
- c.push_back(0);
- z = true;
- }
- else if ((b1[i] == 1) && (b2[i] == 1) && (z == true))
- {
- c.push_back(1);
- z = true;
- }
- }
- }
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement