C# Programming - Operators - Discussion

Discussion :: 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);

[A]. 163 92
[B]. 92 163
[C]. 192 63
[D]. 0 1

Answer: Option A

Explanation:

No answer description available for this question.

Veni said: (Jun 1, 2011)  
Hi please tell me how its work.

Rohit said: (Jul 21, 2011)  
Please explain all steps and it's working rule.

Abhijit Marne said: (Jul 24, 2011)  
11110111 & 10101011 = 10100011 ie 163
11110111 | 10101011 = 01011100 ie 92

Kavitha said: (Jul 30, 2011)  
I couldn't understand that how it works. Please explain the steps.

Vakul Saini said: (Aug 7, 2011)  
Please please give me the description how is this 163 92 ?

Sruthi said: (Aug 23, 2011)  
(0xF7)its in hexadecimal lang convert it into binary then value is 11110111 similarly (0xAB)value is 10101011.

Add these two numbers you will get the value as 10100011 ie binary value convert into decimal ie 163, and

Subtract those two numbers you get the value as 01011100 decimal value is 92.

Bhairav said: (Sep 14, 2011)  
Its right.

Gggggg said: (Sep 14, 2011)  
Thank you bhairav!

Bhavik said: (Nov 28, 2011)  
Thank you sruti

Anandhajothi.S said: (Jan 10, 2012)  
How to work this problem ?

Robin5480@Gmail.Com said: (Jan 21, 2012)  
Thanks to Shruthi.

Bhargav Pandya said: (May 23, 2012)  
Thanks Abhijit Marne.

Joao Lourenco said: (Jun 7, 2012)  
@Sruthi You need to AND the numbers, not ADD them.

Swapon Chandra Dash said: (Jul 20, 2012)  
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

Uppy said: (Aug 12, 2012)  
What is the use of 0x ?

Abi said: (Aug 21, 2012)  
Whats the use of 0x?, why it is not included in calculation?

Debkumar said: (Aug 22, 2012)  
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.

Deeksha said: (Aug 25, 2012)  
Whats the use of 0x?

Gaurav said: (Sep 18, 2012)  
0x is for indicating to the compiler that the no. is in hexadecimal.
A 0 is prefixed to indicate an octal no. .

Rishabh said: (Sep 18, 2012)  
Thanks sruti for explanation. You are great it was very easy.

Sajila said: (Dec 18, 2012)  
0x means hexadecimal value.

Arif said: (May 26, 2014)  
I don't understand please explain how to convert hexadecimal to decimal?

Arif said: (May 27, 2014)  
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.

Savu said: (Oct 11, 2014)  
I think @Arif provided the best explanation for this. Cheers buddy.

Swethasai said: (Jan 2, 2015)  
Excuse me I have one doubt in above explanation how come 10100011 is equal to 163 can anybody explain I am not able to understand.

Pooja Uttam said: (Jan 6, 2015)  
128 64 32 16 8 4 2 1.
1 0 1 0 0 0 1 1 => 128+32+2+1 = 163.

Revathi said: (May 23, 2015)  
What about 92?

Sailu said: (Jun 1, 2015)  
@Swethasai I'm giving clarification for your doubt.

Here 10100011 convert into decimal number 128+0+32+0+0+0+2+1 = 163.

Mamatha said: (Jul 13, 2015)  
Here is the total procedure to compute the value.

1 0 1 0 0 0 1 1.

2^7*1 2^6*0 2^5*1 2^4*0 2^3*0 2^2*0 2^1*1 2^0*1.

128+0+32+0+0+0+2+1 = 163.

Aparna said: (Aug 8, 2015)  
I have one doubt in or ^ operator because or operator explain that if both value are true than answer should be true or infect one value are also true than answer will true.

Like 10101100.

10011001.

Answer = 10111101.

Sai said: (Feb 25, 2016)  
How to identify f = 15.... a = 10?

Siva said: (Apr 12, 2016)  
For simple calculations use these code for fast conversion for decimal to binary and binary to desired values "8421".

Hexadecimal values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.
A =10
So, we take 8 4 2 1
=> 1 0 1 0 = 8 + 2 = 10.

F = 15
So, we take 8 4 2 1
=> 1 1 1 1= 8 + 4 + 2 + 1 = 15.

Kumar said: (Dec 19, 2019)  
OR operator

how it is possible ?
11110111
10101011
_________
01011100 = 92

OR operator
1 1 T
1 0 T
0 1 T
0 0 F

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.