Live data from Hacker News

Calculate n + 1 without using + or - or * or /

news.ycombinator.com

1–10 of 19 posts

Re: Calculate n + 1 without using + or - or * or /

#5
Arbitrary addition, subtraction and multiplication without arithmetic signs.

int add( int a, int b ) { while ( a ) { int c = a & b; b ^= a; a = c int sub( int a, int b ) { return add( a, add( ~b, 1 ) ); }

int mul( int a, int b ) { int c = 0; while ( a ) { if ( a & 1 ) c = add( c, b ); a >>= 1; b <<= 1; } return c; }

Re: Calculate n + 1 without using + or - or * or /

#10
Could do lookup tables like the old CADET system did. http://www.websters-online-dictionary.org/definitions/IBM+16...

In some situations you may be data rich but function poor. Like embedded devices where you have a limited instruction set, 128bytes of RAM, but access to megs of ROM for program/data.

Post reply on HN