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,533 other followers

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: