You don't need to shift to 'clear' some undesired bits, just use and operator.

I will describe you pseudo code:

1) Construct a mask. By example if you want bits 4 to 9, your mask will be 000000000000001111110000

2) Apply the mask to the original number by example to: 00001111000011110000111100001111

Result will be (I hope): 00000000000000000000001100000000

3) Now shift to the right using the lower value (4 in this example)

Result will be (I hope again): 00000000000000000000000000110000

4) Your desired bits are now in first 6 bits.

To build your mask (1):

int mask = (1<<(high-low+1))-1)<<low;

To apply the mask and shift (2) and (3):

int desiredBits = (myNumber & mask)>>low;

So, if you join all:

int desiredBits = (myNumber & ((1<<(high-low+1))-1)<<low))>>low;

I guess it can be reduce to:

int desiredBits = (myNumber>>low) & (1<<(high-low+1))-1);

I will describe you pseudo code:

1) Construct a mask. By example if you want bits 4 to 9, your mask will be 000000000000001111110000

2) Apply the mask to the original number by example to: 00001111000011110000111100

Result will be (I hope): 00000000000000000000001100

3) Now shift to the right using the lower value (4 in this example)

Result will be (I hope again): 00000000000000000000000000

4) Your desired bits are now in first 6 bits.

To build your mask (1):

int mask = (1<<(high-low+1))-1)<<low;

To apply the mask and shift (2) and (3):

int desiredBits = (myNumber & mask)>>low;

So, if you join all:

int desiredBits = (myNumber & ((1<<(high-low+1))-1)<<low

I guess it can be reduce to:

int desiredBits = (myNumber>>low) & (1<<(high-low+1))-1);