Assume the following declaration unsigned k 19 What will be
Solution
Solution:
The first statement will be solved as follows:
k=19 and 0x0007=7
now binary value for both will be
k=10011 and 7= 0111 or 00111
now, j=k & 0x0007 will give
10011 & 00111 (binary AND gives 1 if bit is 1 in both operands)
=00011= 3
hence j=3
The second statement will be solved as follows:
k=19 and 0x0010=16
now binary value for both will be
k=10011 and 16= 10000
now, j=k ^ 0x0010 will give
10011 ^ 10000 (binary XOR gives 1 if bit is 1 in any of the operand otherwise 0)
=00011 = 3
hence j=3
The third statement will be solved as follows:
k=19 and 0x0007=7
now binary value for both will be
k=10011 and 7= 00111
now, j=k | 00111 will give
10011 | 00111 (binary OR gives 1 if bit is 1 in either operand or in both)
=10111 = 23
hence j=23
The fourth statement will be solved as follows:
k=19 and 0x0007 = 7
now binary value for both will be
k=10011 and 7= 0x0007
now, j=k >> 2 & 0x0007 will give
first we will solve >> operator which is binary right shift. It shifts the left operand value to right with bits given in right operand.
10011>>2 & 10000
= 00100 & 10000
= 00000 = 0
hence j= 0
The fifth statement will be solved as follows:
k<<2
= 10011 << 2
on applying << operator which is binary left shift. It shifts the left operand value to left with bits given in right operand.
01100 =12
hence k will be 12

