From 《The C Programming Language》 Page 49

Add function: unsigned getbits(unsigned x, int p, int n)
    get n bits from position p