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