Log In  

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
P#93390 2021-06-12 20:28 ( Edited 2021-06-14 17:49)

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
P#93404 2021-06-13 05:55

[Please log in to post a comment]