www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/30/09:30:34

From: horst DOT kraemer AT snafu DOT de (Horst Kraemer)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: 64k demo
Date: Tue, 30 Jun 1998 13:18:42 GMT
Organization: Unlimited Surprise Systems, Berlin
Lines: 37
Message-ID: <3598cb4a.3116283@news.snafu.de>
References: <008b01bda38e$369d3d80$364e08c3 AT arthur> <35ac0bc8 DOT 13244573 AT news DOT Austria DOT EU DOT net>
NNTP-Posting-Host: n164-83.berlin.snafu.de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Mon, 29 Jun 1998 22:14:58 GMT, sparhawk AT eunet DOT at (Gerhard Gruber)
wrote:

>>You don't seem to understand what I mean. There is a fundamental difference
>>between arethmetic and logical shifting. Arethmetic shifting shifts the data
>>(bytes, words or longs) but keeps the sign bit intact. Logical shifting
>>treats the sign bit as any other bit in the byte/word/long.

>>So for instance, aretmetically shifting left the value -2 would give the
>>result -4; logically shifting left -2 would give 4.

>I think this is wrong. shifting left -2 always gives -4 because the bit
>pattern still has the highest bit set. in hex this would be -2 = 0xFFFE and a
>shift would result in 0xFFFC which still is -4. Problems would occure if you
>shift left a value like 0x8001 because then the bit that shows the sign is
>moved out and the result would be 0x0002 instead of 0x8002.

What "arithmetic shift" really does depends on the signed integer
model of the processor. In a sign/magnitude implementation a 8 bit
signed int with the value -2 is

	10000010

A correct arithmetic shift left on this system would produce -4 alias

	10000100

too, because here it would mean "shift bits #0 to #6 only". If signed
integers are implemented as 2's complement as on INTEL based machines,
a "logical left shift" and an "arithmetic left shift" are the same
operation. Arithmetic shift_left by 1 with signed integers overflows
whenever bits #7 and #6 are not identical.

 
Regards
Horst

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019