TheAlgorithms / C-Plus-Plus

Collection of various algorithms in mathematics, machine learning, computer science and physics implemented in C++ for educational purposes.
https://thealgorithms.github.io/C-Plus-Plus
MIT License
30.79k stars 7.29k forks source link

Fix binary addition logic in add_strings function #2862

Closed chitvs closed 2 weeks ago

chitvs commented 1 month ago

Description of Change

This pull request addresses a bug in the add_strings function located in divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp. The original implementation incorrectly used bitwise XOR and character casting for binary addition, leading to incorrect results during binary multiplication. The updated code uses proper integer arithmetic to handle binary addition correctly, ensuring accurate summation of binary strings.

Fixes #2848 (Incorrect Binary Addition Logic in add_strings).

Checklist

Notes: This fix corrects the binary addition logic, ensuring accurate results for binary multiplication.

chitvs commented 4 weeks ago

Hi @Panquesito7 and @realstealthninja, is there anything else needed to finalize this PR? Thanks!

Best, chitvs