Tests if an integer is power of two : Integer « Date Type « Android

Tests if an integer is power of two

  Copyright (C) 2009,2010  Tobias Domhan

    This file is part of AndOpenGLCam.

    AndObjViewer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AndObjViewer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AndObjViewer.  If not, see <http://www.gnu.org/licenses/>.
//package edu.dhbw.andar;

 * @author Tobias Domhan
 class GenericFunctions {
   * tests if an integer is power of two
   * source: http://www.devmaster.net/forums/showthread.php?t=1728
   * @param value
   * @return
  static final boolean isPowerOfTwo (int value)  {
    if(value != 0) {
      return (value & -value) == value;
    } else {
      return false;



Related examples in the same category

1.Integer To One Byte
2.Integer To Two Bytes
3.Integer To Four Bytes
4.One Byte To Integer
5.Two Bytes To Integer
6.List to int[]
7.Convert an integer value to its byte array representation
8.Convert a byte array integer (4 bytes) to its int value
9.Convert a byte array representing an unsigned integer (4bytes) to its long value
10.fahrenheit To Celsius, celsius To Fahrenheit
11.Padding Int value