Skip to content

Instantly share code, notes, and snippets.

@kishida
Created January 23, 2016 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kishida/af8c39ad57104db5774e to your computer and use it in GitHub Desktop.
Save kishida/af8c39ad57104db5774e to your computer and use it in GitHub Desktop.
Add only with logical operation for general
public class AddLogical {
public static void main(String[] args) {
int a = 231;
int b = 35;
System.out.printf("%d + %d = %d%n", a, b, a + b);
while(b != 0){
int c = a ^ b;
b = (a & b) << 1;
a = c;
}
System.out.println(a);
}
}
@kishida
Copy link
Author

kishida commented Jan 23, 2016

231 + 35 = 266
266

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