Is power of two

From Director Online Wiki
Jump to: navigation, search
--/******
--* IS POWER OF TWO
--****
--* @Param  : 'x' <Integer>
--* @Return : ''  <Boolean>
--***/
on mIsPowerOfTwo( x )
  if Not(IntegerP(x)) then return( FALSE )
  x = max(x, -x)
  return( Not(bitAnd(x, x-1)) - ((x = 0) OR (x = 1)) )
end
--*/