Encoders
Hub for Computer Whizzes Register to join us

Encoders > More... > C > Program

/* Function that gets n bits from postion p. */

#include <stdio.h>

unsigned getbits(unsigned x, int p, int n);

main()
{
        printf("%u\n",getbits(58,4,3));
}

unsigned getbits(unsigned x, int p, int n)
{
        return x>>p+1-n  & ~(~0<<n);
}