I was working on a project, when I realized that checking if a bit is set would be much easier to understand so I made this function that checks if a bit is set.
function bit(v,b) val=((flr(v/b)*b)%(b*2))==b --checks if the bit is set return val --returns true if the bit is set and returns false if the bit is not set end |



a more cannon & faster way to do is called bit masking:
-- v: value to test -- b: bit index [0,31] function bit(v,b) -- shift bit to correct position -- mask input value return v&(0x0.0001<<b)!=0 end |
[Please log in to post a comment]