Java 1.5 (5.0) Changes to the API: several of the new bit manipulation methods in Integer. : BitSet « Collections Data Structure « Java






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

Java 1.5 (5.0) Changes to the API: several of the new bit manipulation methods in Integer.
  
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 BitSetThe use of BitSet
2.Manipulating the BitSetManipulating the BitSet
3.Another Bitset demoAnother Bitset demo
4.Operations on series of numbers
5.BitOHoney
6.BitOps
7.Convert bitset to int array and string
8.Implementation of a bit map of any size, together with static methods to manipulate int, byte and byte[] values as bit maps
9.Operations on bit-mapped fields.