Originally posted by nagaraj raja:
Hai,
This is nagaraju i am confusing how this output is coming plz explain this code
how.plz explain
Hi Nagaraj,
The answer is absolutely correct. Here's how:
We have b = 5.
Now, b << 33 means b is to be shifted left by 33 bits with zero fill on the right.
If we convert 5 into the binary form, we get :
0000 0000 0000 0000 0000 0000 0000 0101.
Shifting left one bit at a time gives ...
1) 0000 0000 0000 0000 0000 0000 0000 1010
2) 0000 0000 0000 0000 0000 0000 0001 0100
3) 0000 0000 0000 0000 0000 0000 0010 1000
4) 0000 0000 0000 0000 0000 0000 0101 0000
5) 0000 0000 0000 0000 0000 0000 1010 0000
6) 0000 0000 0000 0000 0000 0001 0100 0000
7) 0000 0000 0000 0000 0000 0010 1000 0000
8) 0000 0000 0000 0000 0000 0101 0000 0000
9) 0000 0000 0000 0000 0000 1010 0000 0000
10) 0000 0000 0000 0000 0001 0100 0000 0000
11) 0000 0000 0000 0000 0010 1000 0000 0000
12) 0000 0000 0000 0000 0101 0000 0000 0000
13) 0000 0000 0000 0000 1010 0000 0000 0000
14) 0000 0000 0000 0001 0100 0000 0000 0000
15) 0000 0000 0000 0010 1000 0000 0000 0000
16) 0000 0000 0000 0101 0000 0000 0000 0000
17) 0000 0000 0000 1010 0000 0000 0000 0000
18) 0000 0000 0001 0100 0000 0000 0000 0000
19) 0000 0000 0010 1000 0000 0000 0000 0000
20) 0000 0000 0101 0000 0000 0000 0000 0000
21) 0000 0000 1010 0000 0000 0000 0000 0000
22) 0000 0001 0100 0000 0000 0000 0000 0000
23) 0000 0010 1000 0000 0000 0000 0000 0000
24) 0000 0101 0000 0000 0000 0000 0000 0000
25) 0000 1010 0000 0000 0000 0000 0000 0000
26) 0001 0100 0000 0000 0000 0000 0000 0000
27) 0010 1000 0000 0000 0000 0000 0000 0000
28) 0101 0000 0000 0000 0000 0000 0000 0000
29) 1010 0000 0000 0000 0000 0000 0000 0000
After this step, the 1 in the most significant bit place, is shifted back to the least significant bit position by left shift
30) 0100 0000 0000 0000 0000 0000 0000 0001
31) 1000 0000 0000 0000 0000 0000 0000 0010
32) 0000 0000 0000 0000 0000 0000 0000 0101
33) 0000 0000 0000 0000 0000 0000 0000 1010
If we convert the last binary number into decimal, we get 10 which is the required answer.
Hope this solves your confusion !!