Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add Binary addition algorithm in C++ #3030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Sujalgupta2p wants to merge 1 commit into TheAlgorithms:master
base: master
Choose a base branch
Loading
from Sujalgupta2p:patch-4

Conversation

@Sujalgupta2p
Copy link

@Sujalgupta2p Sujalgupta2p commented Oct 6, 2025

feat: Add Binary addition algorithm in C++

This program adds two binary numbers given as strings and returns their sum as a binary string.

About

This algorithm solves the problem of adding two binary numbers without using built-in base conversion functions.
It is based on LeetCode Problem 67 — Add Binary.

How it works

  1. Traverse both strings from right to left (least significant bit first).
  2. Add corresponding bits plus the carry.
  3. Append (sum % 2) to the result and update carry = sum / 2.
  4. Reverse the final result to get the correct binary sum.

Example

Input: a = "1010", b = "1011"
Output: "10101"

Reference

https://en.wikipedia.org/wiki/Binary_arithmetic

✅ Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work — I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file.
  • All new C++ files are placed inside an existing directory.
  • All filenames are lowercase characters with underscores (no spaces or dashes).
  • All functions and variable names follow C++ naming conventions (snake_case or camelCase).
  • All function parameters and return values are clearly defined.
  • All new algorithms include at least one URL that points to Wikipedia or another explanation.

this program adds two binary numbers given as strings and returns their sum as a binary string.
Copy link
Author

Hi! My PR adds a binary addition algorithm in C++.
Could someone please review it and approve the workflow so it can be merged?
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Panquesito7 Panquesito7 Awaiting requested review from Panquesito7 Panquesito7 is a code owner

@realstealthninja realstealthninja Awaiting requested review from realstealthninja realstealthninja is a code owner

1 more reviewer

@sgindeed sgindeed sgindeed approved these changes

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /