Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Type the following program : #include <stdio.h> #define Mask1 0x04 #define Mask2

ID: 3750510 • Letter: T

Question

Type the following program :

#include <stdio.h>

#define Mask1 0x04

#define Mask2 0xFE

int main(void)

{

unsigned char Port0=0x01,Port1=0x03;

Port0=Port0|Mask1;

Port1=Port1&Mask2;

printf("Port0:%x",Port0);

printf("Port1:%x",Port1);

return 0;

}

1. what is the binary representationsfor the Port0,Port1,Mask1, and Mask2 values?

2. what are the binary representation for Port0 and Port1 after the bit manipulations?

3. what is the puprose of the bitwise and operator?

4. what is the purpose of the bitwise or operator?

Explanation / Answer

Ans1. Binary representation of Port0 is 00000001, Port1 is 00000011, Mask1 00000100, Mask2 11111110

Ans2. Binary representation for Port0 after the bit manipulations is 00000101 and Binary representation for Port0 after the bit manipulations is 00000010

Ans3. The bitwise and operator sets the resultant bit as 1 if both the binary numerals have 1 at the same bit position

Ans4. The bitwise and operator sets the resultant bit as 0 if both the binary numerals have 0 at the same bit position