We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a86efc5 commit cf1c998Copy full SHA for cf1c998
sum-of-two-integers/ekgns33.java
@@ -0,0 +1,28 @@
1
+/*
2
+
3
+bit manipulation
4
5
+find carry of each binary digits sum
6
+example
7
8
+ 1 0 1 1
9
+ +0 0 1 0
10
+-----------
11
+ 0 1
12
+ ^carry 1 (1<<2)
13
+ 1
14
15
16
17
+ */
18
+class Solution {
19
+ public int getSum(int a, int b) {
20
+ int carryBitSet;
21
+ while(b != 0) {
22
+ carryBitSet = a & b;
23
+ a = a ^ b;
24
+ b = carryBitSet << 1;
25
+ }
26
+ return a;
27
28
+}
0 commit comments