Skip to content

Instantly share code, notes, and snippets.

@alecbz
Created July 4, 2011 21:51
Show Gist options
  • Select an option

  • Save alecbz/1063990 to your computer and use it in GitHub Desktop.

Select an option

Save alecbz/1063990 to your computer and use it in GitHub Desktop.
increment an integer without arithmetic operators
void inc(int& n)
{
int off = 1;
while(n & off)
{
n ^= off;
off <<= 1;
}
n ^= off;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment