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);
Discussion:
33 comments Page 3 of 4.
Sajila said:
1 decade ago
0x means hexadecimal value.
Arif said:
1 decade ago
I don't understand please explain how to convert hexadecimal to decimal?
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.
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:
1 decade ago
I think @Arif provided the best explanation for this. Cheers buddy.
Swethasai said:
1 decade ago
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:
1 decade ago
128 64 32 16 8 4 2 1.
1 0 1 0 0 0 1 1 => 128+32+2+1 = 163.
1 0 1 0 0 0 1 1 => 128+32+2+1 = 163.
(1)
REVATHI said:
1 decade ago
What about 92?
Sailu said:
1 decade ago
@Swethasai I'm giving clarification for your doubt.
Here 10100011 convert into decimal number 128+0+32+0+0+0+2+1 = 163.
Here 10100011 convert into decimal number 128+0+32+0+0+0+2+1 = 163.
Mamatha said:
1 decade ago
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.
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:
1 decade ago
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.
Like 10101100.
10011001.
Answer = 10111101.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers