if (d >= 0)
clipflags &= ~(1<<i);
EDIT: I understand the bitshifting part (in this case multiplying by 2)
Printable View
if (d >= 0)
clipflags &= ~(1<<i);
EDIT: I understand the bitshifting part (in this case multiplying by 2)
if d is 0 or positive:
clipflags AND by two's complement by i
notes:
1*i=i
two's complement=
0 = 1
1 = 0
so:
1011 will equal to 0100
i do a bitwise AND
godammit! i hate the way i always make mistakes on my posts.
1 is shifted i times to the left
there, or multiplied by 2, i times. or 2^i (not XOR in this case, this is math now, lol)
actually :) ~ is bitwise not so what this does is shift 1 to the right to the i'th bit (counting from the least significant bit), negate or invert every bit (so every bit but the i'th is set) and and(heh) it with clipflags, having the effect of turning off the i'th bit and leaving the rest unchanged.
the two's comliment of n is (~n)+1, remember the two's comliment of zero is zero.
well i wasn't wrong though....
No, it's just two's compliment has a different meaning. Technically ~ is one's compliment but no-one calls it that. To make life more fun people do call binary not or invert negate, and the most common form of signed integers uses two's compliment for negitive ints! I wasn't trying to be mean, take it as a compliment :P
lol, ok :)
yea, u're rite. i said it wrong (two instead of one) but i explained it right. LOL, thanks
yeah, that's right. one's compliment is just flipping the bits. remember, if you want to do 2's compliment, you have to flip the bits then add 1.
so:
1011 ->2's compliment-> 0101