Bit manipulation- for negative numbers
问题 Let the size of integer i=-5 be 2 bytes. The signed bit value at the leftmost bit is '1'(which signifies that it is a negative number). When i am trying to do a right shift operation, should i not expect the '1' at the 15th bit position to shift to 14th position? and give me a high but positive value? What i tried: int i=5; i>>1 // giving me 2 (i understand this) int i=-5 i>>1 // giving me -3 (mind=blown) 回答1: Right shifts of negative values are implementation-defined, [expr.shift]/3 The