Hi,

Probably I found an answer,what is happening is

(((1 << j) & i) != 0)

suppose,i=5

Iter 1: (1<<0)

1)1's binary reprsentation: 00000000 00000000 00000000 00000001<<0 (no changes here)

2) Binary AND: 00000000000000000000000000000001 & 00000000000000000000000000000101=

00000000000000000000000000000001 (a non-zero value) thus it prints 1.

The logic: In each iteration a bit gets left shifted in 1 (1<<j) so that there is exactly one 1 bit in binary representation of 1(left operand). When we AND it with 5's binary repr.,the 1's bit in the 1(left operand), extract's the corresponding 1 bit in 5(if any).This results in, as a non-zero value for the Not Equal to(!=) operator,thus, 1 gets printed.Let's look at it more elaborately(remember iam still in 1st iter):->

00000000000000000000000000000001(at leat one 1 bit in binary),

AND 00000000000000000000000000000101

----------------------------------------

00000000000000000000000000000001 (non- zero result),prints 1

Iter 2

1<<1)

00000000000000000000000000000010

AND 00000000000000000000000000000101

----------------------------------------

00000000000000000000000000000000 (zero result),prints 0

Iter 3

1<<2)

00000000000000000000000000000100

AND 00000000000000000000000000000101

------------------------------------------

00000000000000000000000000000100

and so on

Please correct me if wrong.

THANKS.