=D
Hi folks, i know that there are a lot of examples :google: , but maybe it will be useful for someone
Simple example #1
[java]
public static final boolean isPowerOfTwo( final int pNumber ) throws IllegalArgumentException
{
if ( pNumber <= 0 )
throw new IllegalArgumentException( "MathHelper.isPowerOfTwo: given integer is " + pNumber );
return( ( pNumber & -pNumber ) == pNumber );
//Method #2
//return( ( pNumber & ( pNumber - 1 ) ) == 0 );
}
[/java]
Simple example #2
[java]
public static final boolean isPowerOfTwo( final Image pImage ) throws Exception
{
final int width = pImage.getWidth( );
final int height = pImage.getHeight( );
return( ( ( width & -width ) == width && ( height & -height ) == height ) );
}
[/java]