Use these functions as they are or
as an example to write your own inline bit ops
Code:

//Bit numeration from right to left, starts from 0
// ...76543210 = bit numbers
// ...10010101 = 149
function IsBitSet(val, TheBit){
return((val & (1 << TheBit)) != 0);
}

function BitOn(val, TheBit){
return(val | (1 << TheBit));
}

function BitOff(val, TheBit){
return(val & ((1 << TheBit) ^ 4294967295)); //magic number is max longint ;)
//you can try to write another method to do it without XOR
}

function BitToggle(val, TheBit){
return(val ^ (1 << TheBit));
}


You can add INT() to above funcs if you want to always operate with integers and can't trust to your data
Usage example:
Code:

var IntBefore=19;
var IntAfter;
...
if(IsBitSet(IntBefore,0)){ //exits from 3dgs anyway
exit;
}
...
IntAfter=BitOff(IntBefore, 4); //19 -> 3 (10011 -> 00011)
...
IntAfter=BitOn(IntBefore, 3); //19 -> 27 (10011 -> 11011)
...
IntAfter=BitToggle(IntBefore,3); //19 -> 27
IntAfter=BitToggle(IntAfter,3); //27 -> 19
...


Bit operations are usefull to 'compress' data like 'flags' into one single integer.
Search at forum and you'll find good examples about this stuff from gurus like Grimbler and others.
One more technique for 'fast' MUL and DIV by power of 2 with shifts:
Code:

var IntBefore=16;
IntBefore = IntBefore >> 1; // 8 is 16 DIV 2 (2)
IntBefore = IntBefore >> 2; // 4 is 16 DIV 4 (2*2)
IntBefore = IntBefore << 3; // 128 is 16 MUL 8 (2*2*2)


var is a fixed point integer in C-script, so
Code:

var IntBefore=19;
IntBefore = IntBefore >> 1; // 9.5
IntBefore=19.5;
IntBefore = IntBefore << 1; // 39