Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- unsigned bit_zero(unsigned x, int p, int n){
- const int l = (sizeof(x) << 3) - (p + n);
- unsigned y = ~0;
- return x & ~((((y << l) >> l) >> p) << p);
- }
- int main(void){
- unsigned x = 0xFFFFFFFFU;
- printf("%08X\n", bit_zero(x, 0, 4));
- printf("%08X\n", bit_zero(x, 8, 16));
- printf("%08X\n", bit_zero(x, 16, 8));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement