Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Calculate n + 1 without using + or - or * or /.
int add( int a, int b ) { while ( a ) { int c = a & b; b ^= a; a = c << 1; } return b; }
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; }
There are no comments on this comment yet.
int add( int a, int b ) { while ( a ) { int c = a & b; b ^= a; a = c << 1; } return b; }
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; }