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 1 of 4.
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)
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.
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.
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. .
A 0 is prefixed to indicate an octal no. .
Sajila said:
1 decade ago
0x means hexadecimal value.
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.
Arif said:
1 decade ago
I don't understand please explain how to convert hexadecimal to decimal?
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers