In Khalid Mughal's book question no. 3.14 on the page 73 goes like this: Given a variable x of type int (which may contain a negative value), which are correct ways of doubling the value of x? Select al valid answers. (a) x << 1 ; (b) x = x * 2 ; (c) x *= 2 ; (d) x += x ; (e) x <<= 1 ;
The correct answer given in the book is b, c, d and e. b, c and d are alright. But will e allso be valid? Suppose, x is a negative number. will x <<= 1 really make it double?
Mughal Q3.14 ------------ Thanks Jessica Sant. I din't have the picture of -ve patterns in mind at that time. I still remember how beautiful the bit pattern of -ve numbers are! They are realy cleverly made.