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.
- SAR is the artithmetic shift right.
- SHR is the binary/logical shift right.
–jeroen






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