This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: portable signed right shift
- To: nbecker at fred dot net
- Subject: Re: portable signed right shift
- From: Alexandre Oliva <aoliva at redhat dot com>
- Date: 27 Mar 2001 18:53:37 -0300
- Cc: gcc at gcc dot gnu dot org
- Organization: GCC Team, Red Hat
- References: <x88puf2dic0.fsf@adglinux1.hns.com>
On Mar 27, 2001, nbecker@fred.net wrote:
> So what is an efficient, portable way to get a signed right shift?
Right shift as unsigned, then sign-extend it by hand:
((unsigned)foo >> M) ^ (1 << (N - 1)) - (1 << (N - 1))
You'll generally want M+N to be the width of the target type.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me