Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: [ot] when using >>, filling with 0 or 1

Author: Heiner Marxen

Date: 12:54:16 10/05/02

Go up one level in this thread


On October 05, 2002 at 14:38:12, Antonio Dieguez wrote:

>hi, dumb question. In a book i saw when using the >> operator, with signed
>numbers, it is dependant on the machine if it is filled the left with 0 or 1. I
>supossed it were always 0. May be in practice it is always 0 in pcs, is that the
>case? should i be worried about?

It depends on the type and possibly the value of the (left) operand:
unsigned >> does always fill (high) zeroes (halving the value)
signed non-negative value >> does also fill zeroes.
Both is guaranteed by ANSI-C (6.3.7).

Doing a >> with a negative value is "implementation defined".

Mostly it fills the sign bit, i.e. a 1-bit.
That is similar to halving the value (except for -1).
But you cannot (portably) rely on this behaviour.

Shifting is best done with unsigned quantities.

>thank you.

Cheers,
Heiner



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.