in reply to Implementing a signed/sign-propagating right bitwise shift

Make negative numbers positive, shift them and make them negative again:

sub SRshift { $_[0] < 0 ? -( -$_[0] >> $_[1] ) : $_[0] >> $_[1] }

Should work on any platform regardless of native integer size.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: Implementing a signed/sign-propagating right bitwise shift
by LonelyPilgrim (Beadle) on Feb 16, 2012 at 18:56 UTC
    Thanks. This is the most elegant way I've seen so far, and I think I now understand the math of what exactly it is I'm trying to do. (I would vote this up but I'm now out of votes for the day; I only got 2.)