Paste: BitSet
Author: | bearded_oneder |
Mode: | java |
Date: | Wed, 16 Feb 2011 15:57:57 |
Plain Text |
package Chap_02_Keywords_Types_Vars;
import com.sun.org.apache.xalan.internal.xsltc.dom.BitArray;
import java.util.BitSet;
@author
public class PrimitiveTypeDemotion {
public PrimitiveTypeDemotion() {
BitSet bs = new BitSet(8);
System.out.println("Declared length: " + bs.length());
for (int i = 7; i >= 0; i--) bs.set(i, true);
System.out.println("Flipped length: " + bs.length());
printBits(bs);
bs.flip(1);
bs.flip(3);
printBits(bs);
System.out.println("Value = " + bs);
}
short convertBoolean (boolean b){
if(b) return 1;
return 0;
}
void printBits(BitSet bs){
for (int i = 7; i >= 0; i--) {
System.out.print(convertBoolean(bs.get(i)));
}
System.err.println("");
}
}
New Annotation