Bitwise operation problem

Another bitwise problem I'm working on now is this:

Code:

`/* `

* bitMask - Generate a mask consisting of all 1's

* lowbit and highbit

* Examples: bitMask(5,3) = 0x38

* Assume 0 <= lowbit <= 31, and 0 <= highbit <= 31

* If lowbit > highbit, then mask should be all 0's

* Legal ops: ! ~ & ^ | + << >>

* Max ops: 16

* Rating: 3

*/

int bitMask(int highbit, int lowbit) {

return 2;

}

Anyway, here's my solution to this problem:

Code:

`/* `

* bitMask - Generate a mask consisting of all 1's

* lowbit and highbit

* Examples: bitMask(5,3) = 0x38

* Assume 0 <= lowbit <= 31, and 0 <= highbit <= 31

* If lowbit > highbit, then mask should be all 0's

* Legal ops: ! ~ & ^ | + << >>

* Max ops: 16

* Rating: 3

*/

int bitMask(int highbit, int lowbit) {

int i = 0, j = 0;

i = ~i;

i <<= highbit + 1;

j = ~j;

j <<= lowbit;

i ^= j;

return i & j;

}

My code works fine except for one case: when the highbit is 31.

Somehow the bitwise operator works when it's:

Code:

`i <<= 31; // i is 11111111111111111111111111111111 (32 digits)`

But it won't shift the leftmost significant bit when I do this:

Code:

`i <<= 32; // nothing happens. in the next line, i is still -1`

Can anyone tell me why my compiler won't shift the entire thing to the left? (I'm using VC++ 2003, btw)

And how do I go about it?