C# Programming - Operators - Discussion

Discussion Forum : Operators - General Questions (Q.No. 2)
2.
What will be the output of the C#.NET code snippet given below?
byte b1 = 0xF7;
byte b2 = 0xAB;
byte temp;
temp = (byte)(b1 & b2);
Console.Write (temp + " ");
temp = (byte)(b1^b2);
Console.WriteLine(temp);
163 92
92 163
192 63
0 1
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
33 comments Page 2 of 4.

Arif said:   1 decade ago
1st binary value is 1111(f=15)0111(7).
2nd binary value is 1010(A=10)1011(B=11).

The condition is "&" that means "Evaluates to true only if both variables are true either false"
11110111
10101011
--------
10100011 = 163 decimal.

And second condition is "^" That means "Evaluates to true if one variable is true otherwise false"
11110111
10101011
--------
01011100 = 92 decimal.
Ans: 163, 92.

Arif said:   1 decade ago
I don't understand please explain how to convert hexadecimal to decimal?

Sajila said:   1 decade ago
0x means hexadecimal value.

Rishabh said:   1 decade ago
Thanks sruti for explanation. You are great it was very easy.

Gaurav said:   1 decade ago
0x is for indicating to the compiler that the no. is in hexadecimal.
A 0 is prefixed to indicate an octal no. .

Deeksha said:   1 decade ago
Whats the use of 0x?

Debkumar said:   1 decade ago
1st binary value is 1111(f=15)0111(7)=247 decimal
2nd binary value is 1010(A=10)1011(B=11)=171 decimal
Add these two numbers you will get the value as (11110111+10101011)=110100010 ie binary value convert into decimal ie (247+171)=418, and

Subtract those two numbers you get the value as (11110111-10101011)=1001100 decimal value is (247-171)=76.

Abi said:   1 decade ago
Whats the use of 0x?, why it is not included in calculation?

Uppy said:   1 decade ago
What is the use of 0x ?

Swapon chandra dash said:   1 decade ago
b1 = 1111(F) 0111(7) = OxF7
b2 = 1010(A) 1011(B) = OxAB
-----------------------
b1 & b2 = 1010 0011
|||| ||||
|||| |||----- = 1*1 = 1
|||| ||------ = 2*1 = 2
|||| |------- = 4*0 = 0
|||| -------- = 8*0 = 0
|||------------- = 16*0 = 0
||-------------- = 32*1 = 32
|--------------- = 64*0 = 0
---------------- = 128*1 = 128
----------------
b1 & b2 = 163


==========================================

b1 = 1111(F) 0111(7) = OxF7
b2 = 1010(A) 1011(B) = OxAB
-----------------------
b1 ^ b2 = 0101 1100
|||| ||||
|||| |||----- = 1*0 = 0
|||| ||------ = 2*0 = 0
|||| |------- = 4*1 = 4
|||| -------- = 8*1 = 8
|||------------- = 16*1 = 16
||-------------- = 32*0 = 0
|--------------- = 64*1 = 64
---------------- = 128*0 = 0
----------------
b1 ^ b2 = 92


Post your comments here:

Your comments will be displayed after verification.