Looking at int 44 - I need Math.CEIL (log(2) 44)binary places to represent 44. (answer 6 places)
6 places:
___ ___ ___ ___ ___ ___
32 16 8 4 2 1
But how can I verify that (for example) a bit is 8checked or not?
A simple solution would be to do:
((1<<3) & 44)>0to check if the bit is set.
But note that behind the scenes the computer translates 44into its binary representation and just checks to see if the bit is set in a bit-wise way.
Another solution is to simply create a binary file through toString(2)or mod%2in a loop
Question
Mathematically Through what formula can I check if a bit is set n'th?
(I would prefer an operation without a loop, but just one math phrase)