|
-
Dec 8th, 2005, 11:01 AM
#1
[RESOLVED] Shift Operators (>> and <<)
I've been dabbling in C# a bit and this has me really stuck against a wall.
Code:
class Test
{
public static void Main()
{
int i = -1000;
Console.WriteLine(i >> 3);
}
}
According to MSDN, this shows -125
Could someone please explain to me how this works?
Thanks in advance
-
Dec 8th, 2005, 12:15 PM
#2
Re: Shift Operators (>> and <<)
-1000 in Signed int32:
10000000 00000000 00000011 11101000
Shift Right 3 (Inv+Lsh on calc)
10000000 00000000 00000000 01111101
Which is -125
Got it, thanks!
-
Dec 8th, 2005, 12:31 PM
#3
Re: [RESOLVED] Shift Operators (>> and <<)
Be careful with that.. You might want to look, but I recall reading there is still a bug in the RTM versions of C# when using the shift operator inside of parentheses like that.. I'll see if I can remember where I found it.
Bill
-
Dec 8th, 2005, 12:32 PM
#4
Re: [RESOLVED] Shift Operators (>> and <<)
I'm only trying to translate some C# to VB. I'm not actually going to be using the operators, just mimicing the functionality in my own class.
Thanks for the heads up though
-
Dec 8th, 2005, 12:33 PM
#5
Re: [RESOLVED] Shift Operators (>> and <<)
http://lab.msdn.microsoft.com/produc...7-95174794a573
this is what I was thinking of. So, atleast it doesn't produce bad code.(and it was in VB at that)
Bill
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|