Write out the results of the following logical operations as

Write out the results of the following logical operations, assuming the variables are all int\'s (16-bit integers). Also assume that the variable \"Port\" is equal to 0x0055 for each line.

A) Port &= 0xfff0;

B) Port |= 15;

C) Port = Port ^ 0x0005;

D) Port = (( Port & ~(0x000f) ) | 0x0020 );

Solution

Given Port = 0x0055.

A) Port &= 0xfff0;

0000 0000 0101 0101 &

1111 1111 1111 0000 =

0000 0000 0101 0000 = 0x50.

B) Port |= 15; //Note that here 15 is a decimal representation, and its equivalent binary value is F.

0000 0000 0101 0101 |

0000 0000 0000 1111 =

0000 0000 0101 1111 = 0x5F.

C) Port = Port ^ 0x0005;

0000 0000 0101 0101 ^

0000 0000 0000 0101=

0000 0000 0101 0000 = 0x50.

D) Port = (( Port & ~(0x000f) ) | 0x0020 );

0000 0000 0101 0101 &

1111 1111 1111 0000 =

0000 0000 0101 0000 |

0000 0000 0010 0000 =

0000 0000 0111 0000 = 0x70.

Write out the results of the following logical operations, assuming the variables are all int\'s (16-bit integers). Also assume that the variable \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site