From: dontmailme AT iname DOT com (Steamer) Newsgroups: comp.os.msdos.djgpp Subject: Re: Right shift Date: Fri, 12 May 2000 14:43:46 GMT Organization: always disorganized Lines: 18 Message-ID: <391c1891.23890473@news.freeserve.net> References: <391C0409 DOT 79567772 AT tiscalinet DOT it> NNTP-Posting-Host: modem-134.michigan.dialup.pol.co.uk X-Trace: newsg4.svr.pol.co.uk 958142627 31095 62.137.73.134 (12 May 2000 14:43:47 GMT) NNTP-Posting-Date: 12 May 2000 14:43:47 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: Forte Free Agent 1.11/32.235 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com night DOT walker AT tiscalinet DOT it wrote: >Why right-shifting ">>" a negative signed int will first turn it >positive? > >4 >>1 = 2 but also -4 >> 1 = 2!! I don't see how you get 2. I get -2. But you shouldn't right-shift negative numbers anyway if you want your code to be portable, because the results are implementation-defined. >What EXACTLY happens? In the case of DJGPP, the compiler uses the SAR instruction. This fills the vacated bits with copies of the sign bit. S.