CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2006
    Posts
    40

    Shift right arithmetic

    I understand shift right arithmetic as shifting right and adding zeros in the places execept for the first place which gets the first bit of the original value as a sign bit. I'm not sure if this is right though. My professor gave me a program that is supposed to shift a value right 3 places and the original value is ffff0000 and the shifted value is ffffe000, and I don't think this is right with the definition I have of arithmetic shifts. I'm not sure if I'm not understanding the concept right, or if his program is just wrong.

  2. #2
    Join Date
    Oct 2006
    Posts
    616

    Re: Shift right arithmetic

    Well, this is exactly right.
    The binary representative of your 32 bit value is:
    Code:
    1111 1111 1111 1111 0000 0000 0000 0000 Binary
      F    F    F    F    0    0    0    0     Hex
    Shifting it right with an Arithmetic shift, the sign bit is duplicated and the result is:
    Code:
    1111 1111 1111 1111 1110 0000 0000 0000 Binary
      F    F    F    F    E    0    0    0     Hex
    Regards,

    Zach
    Last edited by Zachm; April 17th, 2007 at 01:59 AM.

  3. #3
    Join Date
    Sep 2006
    Posts
    40

    Re: Shift right arithmetic

    Thank you so much, I think I was just a little confused about what the shifts actually did.

  4. #4
    Join Date
    Nov 2004
    Posts
    34

    Re: Shift right arithmetic

    This utility gives you a visual representation of what's going on with the SAR (and several other CPU) instructions. Check it out if you like. The small manual also has examples on several useful logical operations.
    Attached Files Attached Files

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

Featured