www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/09/18:32:59

From: George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro ex11.c
Date: 9 Feb 1998 22:17:03 GMT
Organization: Oxford University, England
Lines: 20
Message-ID: <6bnv8v$3ho$1@news.ox.ac.uk>
References: <34DF7294 DOT 21D0 AT home DOT com>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Mon, 09 Feb 1998 13:18:12 -0800 in comp.os.msdos.djgpp Dan
<dyoon AT home DOT com> wrote:

:       hotspot[c] += (random() & 7) - 3;

: what does "random() & 7" do?  i'm figuring random() returns a random
: # of type int maybe?  but i have no idea what the "& 7" does.  the & 7
: is the only thing that i need an explenation for.  any help would be
: much appreciated.

`&' is the bitwise AND operator.  If you don't know what this means, I
suggest you read about boolean operators in a C book.

In this case, `random' returns an integer.  ANDing this with 7 results
in a number from 0 to 7; subtracting three gives a number from -3 to 4.

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

ko tavla fo la lojban

- Raw text -


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