test/java/lang/Long/BitTwiddle.java

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug     4495754
  27  * @summary Basic test for long bit twiddling
  28  * @author  Josh Bloch
  29  *
  30  * @compile -source 1.5 BitTwiddle.java
  31  * @run main BitTwiddle
  32  */
  33 
  34 import java.util.Random;
  35 import static java.lang.Long.*;
  36 
  37 public class BitTwiddle {
  38     private static final int N = 1000; // # of repetitions per test
  39 
  40     public static void main(String args[]) {
  41         Random rnd = new Random();
  42 
  43         if (highestOneBit(0) != 0)
  44             throw new RuntimeException("a");
  45         if (highestOneBit(-1) != MIN_VALUE)
  46             throw new RuntimeException("b");
  47         if (highestOneBit(1) != 1)
  48             throw new RuntimeException("c");
  49 
  50         if (lowestOneBit(0) != 0)
  51             throw new RuntimeException("d");




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug     4495754
  27  * @summary Basic test for long bit twiddling
  28  * @author  Josh Bloch



  29  */
  30 
  31 import java.util.Random;
  32 import static java.lang.Long.*;
  33 
  34 public class BitTwiddle {
  35     private static final int N = 1000; // # of repetitions per test
  36 
  37     public static void main(String args[]) {
  38         Random rnd = new Random();
  39 
  40         if (highestOneBit(0) != 0)
  41             throw new RuntimeException("a");
  42         if (highestOneBit(-1) != MIN_VALUE)
  43             throw new RuntimeException("b");
  44         if (highestOneBit(1) != 1)
  45             throw new RuntimeException("c");
  46 
  47         if (lowestOneBit(0) != 0)
  48             throw new RuntimeException("d");