Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2013
- * Bruno da Silva
- * Bits Mul, Add
- */
- stock doMul(x, y) {
- new p;
- for ( p = 0 ; x ; x >>= 1 , y <<= 1) {
- if (x & 1) {
- for( ; y ; ) {
- p = p ^ y;
- y = (p ^ y) & y;
- y = y << 1;
- }
- }
- }
- return p;
- }
- stock doAdd(a , b) {
- for( ; b ; ) {
- a ^= b;
- b = (a ^ b) & b;
- b <<= 1;
- }
- return a;
- }
- main() {
- printf("4 x 6 = %d", doMul(4,6)); // 24
- printf("4 + 6 = %d", doAdd(4,6)); // 10
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement