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.
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
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
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.
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.
Siva said:
9 years ago
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.
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.
Sruthi said:
1 decade ago
(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.
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.
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.
Kumar said:
6 years ago
OR operator
how it is possible ?
11110111
10101011
_________
01011100 = 92
OR operator
1 1 T
1 0 T
0 1 T
0 0 F
how it is possible ?
11110111
10101011
_________
01011100 = 92
OR operator
1 1 T
1 0 T
0 1 T
0 0 F
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.
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers