Strange Symbol Order

Hi all!
I was reading through the source code of an FPS, and I came across the following part:
1
2
3
4
5
6
static inline bool octacollide(physent *d, const vec &dir, float cutoff, const ivec &bo, const ivec &bs)
{
    int diff = (bo.x^(bo.x+bs.x)) | (bo.y^(bo.y+bs.y)) | (bo.z^(bo.z+bs.z)),
        scale = worldscale-1;
    if(diff&~((1<<scale)-1) || uint(bo.x|bo.y|bo.z|(bo.x+bs.x)|(bo.y+bs.y)|(bo.z+bs.z)) >= uint(worldsize))
       return octacollide(d, dir, cutoff, bo, bs, worldroot, ivec(0, 0, 0), worldsize>>1);


My question is (actually two): what does diff&~ mean, and what does 1<<scale mean?
Thanks in advance!
<< is the bitwise left shift operator. 1<<scale will return the value of scale with the bits shifted (moved) one position to the left.

~ is the bitwise NOT operator. It inverts all the bits in the number (1 becomes 0 and 0 becomes 1). It is applied to ((1<<scale)-1) in this case.

& is the bitwise AND operator. It returns a value where a bit at a certain position is 1 only if the bits in both operands are 1 at that position.

EDIT:
| is the bitwise OR operator. It returns a value where a bit at a certain position is 0 only if the bits in both operands are 0 at that position.

^ is the bitwise XOR operator. It returns a value where a bit at a certain position is 0 only if the bits in both operands are the same at that position.
Last edited on
Ok, thanks!
nice info, i need this too... btw, can you give a link that refer to this? i mean, link that provide an example
Last edited on
Topic archived. No new replies allowed.