Results 1 to 5 of 5

Thread: [RESOLVED] Shift Operators (>> and <<)

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Resolved [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

  2. #2

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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!

  3. #3
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    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
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  4. #4

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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

  5. #5
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    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
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width