Skip to content

Commit 5730582

Browse files
authored
Merge pull request keon#68 from ankit167/add_without_operator
Fixes in comments and code-style
2 parents 4eb5dcd + 911394f commit 5730582

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

bit/add_without_operator.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
"""
2-
The following code adds two numbers without using the '+' operator.
2+
The following code adds two positive integers without using the '+' operator.
33
The code uses bitwise operations to add two numbers.
44
55
Input: 2 3
66
Output: 5
77
"""
88

9+
910
def addWithoutOperator(x, y):
1011
while y != 0:
1112
carry = x & y
1213
x = x ^ y
1314
y = carry << 1
1415
print x
1516

17+
1618
def main():
17-
x,y = map(int,raw_input().split())
18-
addWithoutOperator(x,y)
19+
x, y = map(int, raw_input().split())
20+
addWithoutOperator(x, y)
1921

2022
if __name__ == '__main__':
2123
main()

0 commit comments

Comments
 (0)