Last active
August 29, 2015 14:02
-
-
Save sriramster/13cb5b4fd5615e01b858 to your computer and use it in GitHub Desktop.
bit extraction
This file contains 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
#include <stdio.h> | |
#define bit_ext(val, m, n) \ | |
int k = 1 << (m-1); \ | |
k = k | (k -1); \ | |
k = k ^ (1 << (n + 1)); \ | |
int j = 1 << (n + 1); \ | |
j = j ^ (j - 1); \ | |
k = k ^ j; \ | |
val = val & k; \ | |
val = val >> n; \ | |
int main() | |
{ | |
int i = 0xffff; | |
bit_ext(i, 7, 4) | |
printf("\n %d",i); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment