All I could think of is implementing a full adder in software but I'm thinking there has to be a better solution...help!
Calculate n + 1 without using + or - or * or /
1–10 of 19 posts
Re: Calculate n + 1 without using + or - or * or /
#2Re: Calculate n + 1 without using + or - or * or /
#3Re: Calculate n + 1 without using + or - or * or /
#4how about this (example in ruby): def plus_1(x); arr = []; arr[x] = true; return arr.size; end
Re: Calculate n + 1 without using + or - or * or /
#5int 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 /
#6Re: Calculate n + 1 without using + or - or * or /
#7 int inc(int a) {
int mask = ~a;
/* Assuming a is 32-bit. If 64-bit, add 32-bit shift. */
mask |= mask Re: Calculate n + 1 without using + or - or * or /
#8Google quickly reveals this - http://nscraps.com/C/892-c-program-add-two-numbers-without-u...
Re: Calculate n + 1 without using + or - or * or /
#9plus1 = Succ
Probably not the answer they were looking for, but it was the first thing that came into my head.
Re: Calculate n + 1 without using + or - or * or /
#10In 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.