From 583c91ba97bc269d6a65dcad97e59df259dbdfbb Mon Sep 17 00:00:00 2001 From: Soham Sharad Patil Date: Wed, 31 Dec 2025 18:19:38 +0530 Subject: [PATCH 1/3] Document addition function using bitwise operations Added docstring explaining the bitwise addition method. --- maths/addition_without_arithmetic.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/maths/addition_without_arithmetic.py b/maths/addition_without_arithmetic.py index 409604e4c08a..55e965ede456 100644 --- a/maths/addition_without_arithmetic.py +++ b/maths/addition_without_arithmetic.py @@ -22,7 +22,17 @@ def add(first: int, second: int) -> int: >>> add(-321, 0) -321 """ - while second != 0: + + """ + Add two integers without using arithmetic operators. + + This method uses bitwise operations: + - XOR (^) to add bits without carrying + - AND (&) to calculate carry bits + - Left shift (<<) to move the carry to the correct position + """ + + while second != 0: # Continue until there is no carry left c = first & second first ^= second second = c << 1 From 5793dcb067375b97e7f8015f633fed3d960b8ff5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 Dec 2025 12:51:24 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/addition_without_arithmetic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/addition_without_arithmetic.py b/maths/addition_without_arithmetic.py index 55e965ede456..f1b5220144e1 100644 --- a/maths/addition_without_arithmetic.py +++ b/maths/addition_without_arithmetic.py @@ -31,8 +31,8 @@ def add(first: int, second: int) -> int: - AND (&) to calculate carry bits - Left shift (<<) to move the carry to the correct position """ - - while second != 0: # Continue until there is no carry left + + while second != 0: # Continue until there is no carry left c = first & second first ^= second second = c << 1 From 9a73f07810236abf1fc92e47d488053dd8e82446 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 25 Sep 2026 07:03:39 +0200 Subject: [PATCH 3/3] Refactor addition function documentation and output Updated docstring to clarify the use of bitwise operations for addition. Modified the output format of the result to include both input values. --- maths/addition_without_arithmetic.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/maths/addition_without_arithmetic.py b/maths/addition_without_arithmetic.py index f1b5220144e1..299c526925d8 100644 --- a/maths/addition_without_arithmetic.py +++ b/maths/addition_without_arithmetic.py @@ -8,7 +8,10 @@ def add(first: int, second: int) -> int: """ - Implementation of addition of integer + Add two integers using bitwise operations instead of arithmetic operators. + - XOR (^) to add bits without carrying + - AND (&) to calculate carry bits + - Left shift (<<) to move the carry to the correct position Examples: >>> add(3, 5) @@ -19,17 +22,8 @@ def add(first: int, second: int) -> int: -5 >>> add(0, -7) -7 - >>> add(-321, 0) - -321 - """ - - """ - Add two integers without using arithmetic operators. - - This method uses bitwise operations: - - XOR (^) to add bits without carrying - - AND (&) to calculate carry bits - - Left shift (<<) to move the carry to the correct position + >>> add(-321, 1) + -320 """ while second != 0: # Continue until there is no carry left @@ -46,4 +40,4 @@ def add(first: int, second: int) -> int: first = int(input("Enter the first number: ").strip()) second = int(input("Enter the second number: ").strip()) - print(f"{add(first, second) = }") + print(f"{first = }, {second = }, {add(first, second) = }")