delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/17/10:43:36

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro ex11.c
Date: Sun, 15 Feb 1998 23:49:52 -0800
Organization: Alcyone Systems
Lines: 19
Message-ID: <34E7EFA0.6DF9E92@alcyone.com>
References: <34DF7294 DOT 21D0 AT home DOT com> <34e39746 DOT 1884750 AT news DOT compusmart DOT ab DOT ca>
NNTP-Posting-Host: 165.90.20.242
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Demandred wrote:

> Hmmm... random() returns a random (duh) integer that can be pretty
> huge (0 to MAXINT, IIRC), so I'd guess that the & 7 (bitwise AND with
> 111b) acts like a % 8 (modulus 8)(??).  Why, I don't know... maybe
> bitwise AND is faster than mod?

x%n is the same as x&(n - 1), when n is a power of 2.

Bitwise operations are much, much faster than integer division operators
(/, %).

-- 
         Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
                       Alcyone Systems / http://www.alcyone.com/max/
  San Jose, California, United States / icbm://+37.20.07/-121.53.38
                                     \
                       "Life may be / the product of imperfections."
                                   / (Marclo Gleiser)

- Raw text -


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