View Single Post
Doodil
Senior Member
Join Date: Mar 2012
Old 03-26-2014 , 11:15   Re: How to compare bitstrings(like (1<<1))
Reply With Quote #7

correct me if I'm wrong, but in other programing languages (1|2|3) does not mean "set bit 1, 2 and 3" but "set the bits that are used to represent the numbers 1, 2 and 3". And that means:

1= 001
2= 010
3= 011

and going with this logic (1|2|3) = 011 and (1|2) = 011, so (1|2|3) == (1|2) equals true.


If you want to set bit number X (starting at 0) then you have to left-shift the first bit by X:

(1<<0) = 001 //equals 1
(1<<1) = 010 //equals 2
(1<<2) = 100 //equals 4, not 3



Please correct me if this is any different in sourcemod.
Doodil is offline