C Programming - Bitwise Operators - Discussion

1. 

Left shifting a number by 1 is always equivalent to multiplying it by 2.

[A]. True
[B]. False

Answer: Option A

Explanation:

0001 => 1
0010 => 2
0100 => 4
1000 => 8

Charlie said: (Jul 28, 2010)  
Not always. Bits fall off the end!

printf("%d\n", 1<<33);

Sathuragiri said: (Oct 27, 2011)  
printf("%d\n",1<<33) what is this? it will print what?

Sathuragiri said: (Oct 27, 2011)  
There will be no doubt if they directly given the qn as in binary representation of a number, left shifting it by one is e qual to multiplying it by 2. They hidden the term (Binary representation).

Harshit Sharma said: (Feb 23, 2014)  
It was not mentioned in the que that the no. was in binary representation?

Berci said: (Mar 4, 2014)  
And what if you shift 1000?

Vlknr said: (Dec 11, 2014)  
int a = 1 << 31;

a << 1! = a*2.

Adamk said: (Sep 6, 2015)  
Not always. Think about overflow cases.

David said: (Nov 23, 2016)  
The "answer" is wrong due to the possibility of overflow.

Rahul said: (Dec 12, 2016)  
What about 0 when it is left shifted ? Anybody give me the answer please.

I guess 0 left shifted by 1 becomes 1 which is not divisible by 2.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.