# shift operators

Anonymous

Ranch Hand

Posts: 18944

William Brogden

Author and all-around good cowpoke

Rancher

Rancher

Posts: 13058

6

posted 15 years ago

As I recall, the shift operator ignores the sign. For a 32 bit shift, it masks off the low 5 bits and uses that value, for that reason, a shift of 33 is the same as a shift of one.

Masking the low five bits of -1 gives you 11111 = 31 places shifted.

Shift of long (64 bit) values masks off the low 6 bits.

Bill

Masking the low five bits of -1 gives you 11111 = 31 places shifted.

Shift of long (64 bit) values masks off the low 6 bits.

Bill

Anonymous

Ranch Hand

Posts: 18944

mita

Ranch Hand

Posts: 50

posted 15 years ago

how do we evaluate -1>>-1. The o/p : -1.Is there any rule

that -ve no >>-1 is -1.

Thanks!

shifting by -1, is equivalent to shifting by 31.(-1 + 32 = 31).

So -1 >> -1 equivalent to -1 >> 31 .The result is -1.

When we do shifting by -ve numbers, for a 32bit we add 32 to the negative number & add 64 in case of 64 bits.

Hope it helps.

that -ve no >>-1 is -1.

Thanks!

shifting by -1, is equivalent to shifting by 31.(-1 + 32 = 31).

So -1 >> -1 equivalent to -1 >> 31 .The result is -1.

When we do shifting by -ve numbers, for a 32bit we add 32 to the negative number & add 64 in case of 64 bits.

Hope it helps.