Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!think!ames!amdahl!amdcad!tim
From: tim@amdcad.AMD.COM (Tim Olson)
Newsgroups: comp.lang.c,comp.sys.ibm.pc
Subject: Re: What's Wrong here?
Message-ID: <19390@amdcad.AMD.COM>
Date: Tue, 1-Dec-87 12:04:38 EST
Article-I.D.: amdcad.19390
Posted: Tue Dec  1 12:04:38 1987
Date-Received: Fri, 4-Dec-87 07:08:13 EST
References: <278@westmark.UUCP> <6755@brl-smoke.ARPA> <6855@sunybcs.UUCP> <6761@brl-smoke.ARPA> <312@etn-rad.UUCP>
Reply-To: tim@amdcad.UUCP (Tim Olson)
Organization: Advanced Micro Devices
Lines: 24
Xref: mnetor comp.lang.c:5674 comp.sys.ibm.pc:10668

In article <312@etn-rad.UUCP> jru@etn-rad.UUCP (John Unekis) writes:
|                       ... Microsoft C uses the arithmetic shift whenever 
| you do a >> shift in C. This is nice in a way, because a right shift by 
| one bit is always equal to a divide by two. That is 4 >> 1 = 2, and 
| -4 >> 1 = -2.

This is not true.  First of all, right shift is not guaranteed to be
arithmetic for signed integers.  Second, most computers and languages
define integer divide to round towards zero, not negative infinity. 
Therefore, substituting >> for a division by a power of 2 is not correct
(unless you also include the fixup code for odd negative dividends).

| If it is important
| to you not to propagate the sign bit , I suggest you follow a right shift
| with an and operation such as result = (value >> n) & (32767 >> (n-1)). It
| is a horrible kludge, but it may be easier than coding an assembler routine
| to perform a logical right shift instead of the arithmetic right shift.

Why not just use unsigned operands?  Right shift is required to be
logical (zero-fill) for unsigned ints.

	-- Tim Olson
	Advanced Micro Devices
	(tim@amdcad.amd.com)