Mail Archives: djgpp/1997/05/17/16:20:14
David Jenkins (me AT jenkinsdavid DOT demon DOT co DOT uk) wrote:
: In article <01bc6257$9ed88cc0$LocalHost AT stachowiak>, Helix
: >
: > if ((mouse_b & 1) & (mouse_x > fx) & (mouse_x < lx) & (mouse_y > fy) &
: >(mouse_y < ly))
: > CityBackPix();
: Why do you have each condition in () brackets??
I'm not sure exactly what the precedence is, but I do that too for
clarity.
: And why only the one &'s I thought your HAD to use two &&????
A single & means `bitwise AND'; the double && means logical AND. As an
example, 0 & 1 == 0, 1 & 3 == 1, 5 & 12 == 4, while x && y == 1 iff both x
and y are non-zero. I'm not sure this is very clear; the bitwise AND
returns a 1 in each bit position where that bit in both arguments is set,
while the logical AND returns either TRUE iff both arguments are not
FALSE, otherwise it returns FALSE.
In this case, the line should really read:
if ((mouse_b & 1) && (mouse_x > fx) && (mouse_x < lx)
&& (mouse_y > fy) && (mouse_y < ly)) {...}
(aligned for clarity). The first remains bitwise because its purpose is to
extract the bottom bit of mouse_b. All the others are relating to whether
the comparisons are non-zero. The line would actually work as it was
originally written, but it would probably fail if more than one of the
conditions was not a TRUE/FALSE value.
--
George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Merton College, Oxford
- Raw text -