The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

In Delphi SHR is a SHR; in C >> is a SAR or SHR (via: Shift Right: Delphi vs C | Galfars Lair)

Posted by jpluimers on 2011/11/22

I never knew that >> in C was a SAR/SHR depending if the underlying integer type was signed/unsigned.

In Delphi the SHR is always a SHR operation: it never takes into account the sign.

–jeroen

via: Shift Right: Delphi vs C | Galfars Lair.

2 Responses to “In Delphi SHR is a SHR; in C >> is a SAR or SHR (via: Shift Right: Delphi vs C | Galfars Lair)”

  1. Celal Ergun's avatar

    Celal Ergun said

    I have encountered that in a reverse engineering project. We created test routines but they sometimes failed. We had to write that block in plain assembly.

  2. Eric's avatar

    Eric said

    Taking into account the sign is pointless, you can just divide or multiply by a power of two. Shr on the other hand can’t be expressed in a straightforward fashion if you don’t have the operator.
    In C the above explains the prevalence of unsigned integers and blind casts in bit-aware code. It was a design oversight.

Leave a reply to Eric Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.