Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!brunix!tac From: tac@cs.brown.edu (Theodore A. Camus) Newsgroups: comp.lang.c Subject: shift right arithmetic Message-ID: <49160@brunix.UUCP> Date: 6 Sep 90 02:29:50 GMT Sender: news@brunix.UUCP Reply-To: tac@cs.brown.edu (Theodore A. Camus) Organization: Brown University Department of Computer Science Lines: 27 I would like to do a portable arithmetic right shift in C. Possible solutions and problems : 1) '>>' will _not_ guarantee the result on a signed argument (ANSI & K&R) 2) dividing by a power of 2 will often compile to arithmetic shifts, but only for the smaller powers of 2, not for the full 2^1 - 2^31 shift range. 3) One could test for a negative argument, and if it was negative, use a negate / shift / negate sequence, but there should be a better way. For most compilers, '>>' will differentiate between signed and unsigned arguments, but again K&R and ANSI allows it to be implementation-defined. Any answers ? - Ted CSnet: tac@cs.brown.edu Ted Camus ARPAnet: tac%cs.brown.edu@relay.cs.net Box 1910 CS Dept BITnet: tac@browncs.BITNET Brown University "An ounce of example is worth a pound of theory." Providence, RI 02912