What will be the output of the following C# code? [code] static void Main(string[] args) { byte varA = 10; byte varB = 20;

Giang Phạm

New member
What will be the output of the following C# code?
Code:
 static void Main(string[] args)
 {
     byte varA = 10;
     byte varB = 20;
     long result = varA & varB;
     Console.WriteLine("{0}  AND  {1} Result :{2}", varA, varB, result);
     varA = 10;
     varB = 10;
     result = varA & varB;
     Console.WriteLine("{0}  AND  {1} Result : {2}", varA, varB, result);
     Console.ReadLine();
 }
A. 0, 20
B. 10, 10
C. 0, 10
D. 0, 0
 
Answer: c
Explanation: When ‘OR’ operations is done on the binary values following are the results of OR.
‘OR’ means addition(+) operation.
Code:
                 0 (false) +   0(false)  =   0 (false)
	         1 (True)  +   0(false)  =   1 (True)
	         0(false)  +   1(True)   =   1 (True)
	         1(True)   +   1(True)   =   1 (True)
When using OR operation it gives FALSE only when both the values are FALSE. In all other cases ‘OR’ operation gives ‘true’.
Output :
Code:
          10  AND  20 Result :0.
          10  AND  10 Result :10.
 

Tìm kiếm

Back
Top