# Board index » delphi » TP/BP 7.01 shift bug?

## TP/BP 7.01 shift bug?

In TP 7 (7.01??) and BP 7.01, with

var n : longint; shift : integer;

this executes correctly:

shift := ((n and 63) - 1) shr 1;
if odd( BitVector[ n shr 6] shr shift) then

but this doesn't:

if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1) then

I thought that the bug with shifting a longint was fixed in
version 7.01.  I tried this with TP and BP 7.01.  What's the
problem?

Jud McCranie

## Re:TP/BP 7.01 shift bug?

On Wed, 19 Jan 2000 00:14:11 -0500, Jud McCranie

##### Quote
<jud.mccra...@mindspring.com> wrote:
> In TP 7 (7.01??) and BP 7.01, with

> var n : longint; shift : integer;

> this executes correctly:

>  shift := ((n and 63) - 1) shr 1;
>  if odd( BitVector[ n shr 6] shr shift) then

> but this doesn't:

>  if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1) then

> I thought that the bug with shifting a longint was fixed in
> version 7.01.  I tried this with TP and BP 7.01.  What's the
> problem?

A missing pair of parens. Shift operators are not associative and
binary operators with the same precedence are left associative.

A SHR B SHR C

means

(A SHR B) SHR C

and not

A SHR ( B SHR C)

You should write

if odd( BitVector[ n shr 6] shr (((n and 63) - 1) shr 1) ) then

if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1 ) then

Regards
Horst

## Re:TP/BP 7.01 shift bug?

In article <npha8s40tffponag6fd9k9ghuk6l3je...@4ax.com>,

##### Quote
jud.mccra...@mindspring.com wrote:
> In TP 7 (7.01??) and BP 7.01, with

> var n : longint; shift : integer;

> this executes correctly:

>  shift := ((n and 63) - 1) shr 1;
>  if odd( BitVector[ n shr 6] shr shift) then

> but this doesn't:

>  if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1) then

> I thought that the bug with shifting a longint was fixed in
> version 7.01.  I tried this with TP and BP 7.01.

> What's the problem?

Exactly, _what is the problem?_

Robert
--
Robert AH Prins
prin...@willis.com

Sent via Deja.com http://www.deja.com/

## Re:TP/BP 7.01 shift bug?

##### Quote
horst.krae...@t-online.de (Horst Kraemer) wrote:
>A missing pair of parens. Shift operators are not associative and
>binary operators with the same precedence are left associative.

Whoops!  You're right, my mistake.  (It was late at night when I
did that.)
Jud McCranie

## Re:TP/BP 7.01 shift bug?

Hi !

##### Quote
Jud McCranie <jud.mccra...@mindspring.com> wrote:
> In TP 7 (7.01??) and BP 7.01, with
> var n : longint; shift : integer;
> this executes correctly:
>  shift := ((n and 63) - 1) shr 1;
>  if odd( BitVector[ n shr 6] shr shift) then
> but this doesn't:

I would say that you forgot a bracket in the following line and so the
expression is not calculated exactly !
It should be like this

##### Quote
>  if odd( BitVector[ n shr 6] shr ((n and 63) - 1) shr 1 ) ) then

^^^

I think that should be all.

##### Quote
> I thought that the bug with shifting a longint was fixed in
> version 7.01.  I tried this with TP and BP 7.01.  What's the
> problem?
> Jud McCranie

Hope it helps !
Toralf

## Re:TP/BP 7.01 shift bug?

##### Quote
Toralf Richter <t...@irz763.inf.tu-dresden.de> wrote:
>I would say that you forgot a bracket in the following line and so the
>expression is not calculated exactly !

You're right.  It was late at night, and when I tried to
optimize by putting the variable inline, I didn't do it right,
and when it didn't work, I assumed that it was something related
to the old longint shift bug.

Jud McCranie