in Programming in C
1,213 views
0 votes
0 votes

what does the symbol | represents? If it is logical OR then how does we get the answer as 1088?

in Programming in C
1.2k views

1 Answer

1 vote
1 vote

It is not logical OR, it is bitwise OR.

Foo(4) making value of x = 4

Count = 8, total =4

X right shift by 1, making x = 2

While (2)

Total left shift by 1, making total = 8

Total |= x&1 will bitwise AND x with 1 means all 0 and Total bitwise ORing with all 0 is same. So Total = 8

X right shift to 1, so x=1

Count = 7

While (1)

Total left shift 1, Total=16

x(x=1) bitwise ANDing with 1 means 1 and now Total  bitwise ORing with 1 means adding 1 to Total, so Total = 17

X = 0

Count = 6

While ends

Total left shift by 1, So Total = 17*2^6 

Total = 17*64=1088 Ans

Related questions