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 2 of 4.
Robin5480@gmail.com said:
1 decade ago
Thanks to Shruthi.
Bhargav Pandya said:
1 decade ago
Thanks Abhijit Marne.
Joao Lourenco said:
1 decade ago
@Sruthi You need to AND the numbers, not ADD them.
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
Uppy said:
1 decade ago
What is the use of 0x ?
Abi said:
1 decade ago
Whats the use of 0x?, why it is not included in calculation?
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.
Deeksha said:
1 decade ago
Whats the use of 0x?
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. .
Rishabh said:
1 decade ago
Thanks sruti for explanation. You are great it was very easy.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers