Created
August 9, 2014 11:40
-
-
Save Learath2/36d5d3ac5bc62bb624f1 to your computer and use it in GitHub Desktop.
K&R2 Exercise 2-7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*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