home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!portal!cup.portal.com!Aurelius
- From: Aurelius@cup.portal.com (Mark Christian Barnes)
- Newsgroups: comp.lang.c
- Subject: Re: How to do an efficient ROTATE in C?
- Message-ID: <71576@cup.portal.com>
- Date: Sat, 12 Dec 92 12:49:03 PST
- Organization: The Portal System (TM)
- Distribution: ba
- References: <1992Dec9.033715.3807@kronos.arc.nasa.gov>
- Lines: 21
-
- Eric A. Raymond writes:
-
- |C has those lovely >> and << ops for shifting, but no built in rotate
- |operators?
- |Anyone have an efficent way to trick a compiler into generating a
- |rotate? (either direction is fine).
-
- Most C compilers will do rotates, i.e. logical shifts, using
- the << and >> operators, when the type of argument is UNSIGNED.
- Otherwise arithmetic shifts must be used to preserve the sign
- of the argument.
-
- {
- int sign = -1;
- unsigned unsign = 1;
-
- sign = sign << 2; /* this should be an arithmetic shift */
- unsign = unsign << 2; /* this should be a logical shift */
- }
-
- Regards, Aurelius@cup.portal.com
-