It’s easy to convert Decimal to Binary and vice-versa in any language, but I need a function that’s a bit more complicated.
Given a decimal number and a binary place, I need to know if the binary bit is On or Off (True or False).
Example:
IsBitTrue(30,1) // output is False since 30 = 11110 IsBitTrue(30,2) // output is True IsBitTrue(30,3) // output is True
The function will be called a LOT of times per second, so a fast algorithm is necessary.. Your help is very much appreciated 😀
Print this page out, hang above your monitor
http://graphics.stanford.edu/~seander/bithacks.html
But it’s roughly something like
if ( value & (1 << bit_number) )