#include <stdio.h>

unsigned int getbits(unsigned x, int p, int n) {   //x=312, p=8, n=4
    return (x >> (p-n)) & ~(~0 << n);
    //312=100111000
    //100111000>>4 = 10011 
    //1<<4 = 10000
    //~10000=01111
    //10011 & 01111 = 00011 = 3
}
void main() {
    unsigned int x = 312, res;
    res = getbits(x, 8, 4);
    printf("%d\n", res);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: