Java 1.5 (5.0) Changes to the API: several of the new bit manipulation methods in Integer. : BitSet : Collections Data Structure : Java examples (example source code) Organized by topic

Java
C++
PHP
Java Home »  Collections Data Structure   » [  BitSet  ]  Screenshots 
 



Java 1.5 (5.0) Changes to the API: several of the new bit manipulation methods in Integer.




/*
Java 2, v5.0 (Tiger) New Features
by Herbert Schildt
ISBN: 0072258543
Publisher: McGraw-Hill/Osborne, 2004
*/

public class Bits 
  public static void main(String args[]) { 
    int n = 170// 10101010 
 
    System.out.println("Value in binary: 10101010")
 
    System.out.println("Number of one bits: " 
                       Integer.bitCount(n))
 
    System.out.println("Highest one bit: " 
                       Integer.highestOneBit(n))
 
    System.out.println("Lowest one bit: " 
                       Integer.lowestOneBit(n))
 
    System.out.println("Number of leading zeros : " 
                       Integer.numberOfLeadingZeros(n))
 
    System.out.println("Number of trailing zeros : " 
                       Integer.numberOfTrailingZeros(n))
 
    System.out.println("\nBeginning with the value 1, " 
                       "rotate left 16 times.")
    n = 1
    for(int i=0; i < 16; i++) { 
      n = Integer.rotateLeft(n, 1)
      System.out.println(n)
    
  
}

           
       
Related examples in the same category
1.  The use of BitSet The use of BitSet
2.  Manipulating the BitSet Manipulating the BitSet
3.  Another Bitset demo Another Bitset demo
4.  Operations on series of numbers
5.  BitOHoney
6.  BitOps
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.