Assume the following declaration unsigned k 19 What will be

Assume the following declaration: unsigned k = 19; What will be the value of j after the following statement ?: j = k & 0x0007/* 0x0007 is in hex */What will be the value of j after the following statement ?: j = k^0x0010/* 0x0010 is in hex */What will be the value of j after the following statement ?: j = k | 0x0007/* 0x0007 is in hex */What will be the value of k after the following statement ?: j = k >> 2 & 0x0007/* 0x0007 is in hex */What will be the value of k after the following statement?: k

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

 Assume the following declaration: unsigned k = 19; What will be the value of j after the following statement ?: j = k & 0x0007/* 0x0007 is in hex */What wi
 Assume the following declaration: unsigned k = 19; What will be the value of j after the following statement ?: j = k & 0x0007/* 0x0007 is in hex */What wi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site