Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int add(int x, int y) {
- int a, b;
- do {
- a = x & y;
- b = x ^ y;
- x = a << 1;
- y = b;
- } while (a);
- return b;
- }
- int main( void ){
- printf( "6 + 3 = %d", add(6,3));
- printf( "6 - 3 = %d", add(6,-3));
- return 0;
- }
- def add(x, y):
- while True:
- a = x & y
- b = x ^ y
- x = a << 1
- y = b
- if a == 0:
- break
- return b
- print "6 + 3 = %d" % add(6,3)
- print "6 - 3 = %d" % add(6,-3)
- >>> 1 << 100
- 1267650600228229401496703205376L
- x = (a << 1) & 0xffffffff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement