Thread: question about what this line might be trying to accomplish

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned
    Join Date
    Jan 2003
    Posts
    1,708

    question about what this line might be trying to accomplish

    I'm not entirely sure about this line of code, its from the original gl quake's source code. Carmack does a lot of funny things at the bit level and I have no friggin clue what they are supposed to be

    the actual part of this is the
    rand()&3) & 1

    the entire context is this:
    any clue what the bitwise and operator is being used for? If i remember correctly if bit A and bit B are 1, then the resulting bit is also a 1, otherwise its a zero if either are 0?
    Code:
    	if ( ((rand()&3) & 1) ||  abs(deltay)>abs(deltax))
    	{
    		tdir=d[1];
    		d[1]=d[2];
    		d[2]=tdir;
    	}
    Oh and this is actually monster code, I guess it randomly chooses a dijrection to move in somehow?

    Thanks if you can help explain this to me

    EDIT: is doing operations on variables faster on the bit level?
    Last edited by Silvercord; 03-21-2003 at 05:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question on grepping multiple words in a line
    By Overworked_PhD in forum Linux Programming
    Replies: 6
    Last Post: 04-11-2009, 11:12 PM
  2. fseek question regarding line number
    By DB66 in forum C Programming
    Replies: 1
    Last Post: 10-18-2008, 07:23 PM
  3. beginners question: write onto command line
    By xximranxx in forum Windows Programming
    Replies: 7
    Last Post: 05-05-2007, 08:49 AM
  4. Command Line arguments question
    By micpi in forum C Programming
    Replies: 7
    Last Post: 04-24-2007, 08:46 PM
  5. Command Line parameters question
    By Cbuild in forum C Programming
    Replies: 4
    Last Post: 11-26-2003, 08:30 PM