C# Programming - Operators - Discussion

Discussion Forum : Operators - General Questions (Q.No. 13)
13.
What will be the output of the C#.NET code snippet given below?
byte b1 = 0xAB;
byte b2 = 0x99;
byte temp;
temp = (byte)~b2;
Console.Write(temp + " ");
temp = (byte)(b1 << b2);
Console.Write (temp + " ");
temp = (byte) (b2 >> 2);
Console.WriteLine(temp);
102 1 38
108 0 32
102 0 38
1 0 1
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
10 comments Page 1 of 1.

Subramanyam said:   1 decade ago
Please give me answer for this Question.

Jitender said:   1 decade ago
First convert 0x99 into decimal it is 153 and after that convert 153 into binary and it is 1011001. We take difference for compliment operator.

And 255-153=102 which is required for first temp.

Rajeev said:   1 decade ago
b1 << b2 --> b1 is left shifted b2 times, causes byte overflow. So temp = 0

b2 >> 2 --> right shift by 2 and padded with 0

b2(153)10011001 --> 00100110 - 38

Usha said:   1 decade ago
Please tel me how to left shift or right shift.

Nidhi said:   1 decade ago
What doesn't "~" do?

Sudeep suman said:   1 decade ago
~ means compliment that means if value is =0 then it will be 1 and vice versa.

Abhishek yadav said:   1 decade ago
What is the meaning of Ox in Ox99?

Anshul said:   10 years ago
How convert binary into decimal? Explain any one?

Anshul jain said:   10 years ago
Please someone tell me b1 << b2.

Who work?

HanLin said:   7 years ago
'0x' represents the hexadecimal number.

Post your comments here:

Your comments will be displayed after verification.