Skip to content

Instantly share code, notes, and snippets.

@Learath2
Created August 9, 2014 11:40
Show Gist options
  • Select an option

  • Save Learath2/36d5d3ac5bc62bb624f1 to your computer and use it in GitHub Desktop.

Select an option

Save Learath2/36d5d3ac5bc62bb624f1 to your computer and use it in GitHub Desktop.
K&R2 Exercise 2-7
/*K&R2 Exercise 2-7 "invert"*/
#include <stdio.h>
unsigned invert(unsigned, int, int);
int main()
{
}
unsigned invert(unsigned x, int p, int n)
{
return (~(~(~0 << n) << p + 1 - n) & x) | ((~(x >> p + 1 - n) & ~(~0 << n)) << p + 1 - n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment