本文整理汇总了Java中java.util.BitSet.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java BitSet.toByteArray方法的具体用法?Java BitSet.toByteArray怎么用?Java BitSet.toByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.BitSet
的用法示例。
在下文中一共展示了BitSet.toByteArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toByteArray
import java.util.BitSet; //导入方法依赖的package包/类
@VisibleForTesting // testing and/or mock
public static byte[] toByteArray(
boolean riderDetected,
boolean riderDetectPad1,
boolean riderDetectPad2,
boolean icsuFault,
boolean icsvFault,
boolean charging,
boolean bmsCtrlComms,
boolean brokenCapacitor ) {
BitSet bitSet = new BitSet(8);
bitSet.set(0,riderDetected);
bitSet.set(1,riderDetectPad1);
bitSet.set(2,riderDetectPad2);
bitSet.set(3,icsuFault);
bitSet.set(4,icsvFault);
bitSet.set(5,charging);
bitSet.set(6,bmsCtrlComms);
bitSet.set(7,brokenCapacitor);
return bitSet.toByteArray();
}
示例2: changePositon
import java.util.BitSet; //导入方法依赖的package包/类
@Test
public void changePositon(){
BitSet bitm =new BitSet(Constraints.Threshold_l);
bitm.set(6);
bitm.set(5);
System.out.println(bitm);
byte[] bytes = bitm.toByteArray();
long[] longs = bitm.toLongArray();
System.out.println(bytes[0]);
System.out.println(longs[0]);
int i = bytes[0] >>> 1;
// int i = byteArrayToInt(bytes);
// System.out.println(i);
// int num =i >> 1;
// System.out.println(num);
// byte[] bytes1 = intToByteArray(i);
// bitm = BitSet.valueOf(new byte[]{48});
// System.out.println(bitm);
}
示例3: encodeBits
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Encodes an arbitrary bitstring into a RAPPOR report.
*
* @param bits A bitstring in which only the least significant numBits bits may be 1.
*/
private byte[] encodeBits(BitSet bits) {
BitSet permanentRandomizedResponse = computePermanentRandomizedResponse(bits);
BitSet encodedBitSet = computeInstantaneousRandomizedResponse(permanentRandomizedResponse);
// BitSet.toByteArray only returns enough bytes to capture the most significant bit
// that is set. For example, a BitSet with no bits set could return a length-0 array.
// In contrast, we guarantee that our output is sized according to numBits.
byte[] encodedBytes = encodedBitSet.toByteArray();
byte[] output = new byte[(numBits + 7) / 8];
Verify.verify(encodedBytes.length <= output.length);
System.arraycopy(
encodedBytes, // src
0, // srcPos
output, // dest
0, // destPos
encodedBytes.length); // length
return output;
}
示例4: testBitSet
import java.util.BitSet; //导入方法依赖的package包/类
@Test
public void testBitSet() {
BitSet b = new BitSet(10);
b.set(8);
byte[] a = b.toByteArray();
Util.reverse(a);
assertEquals(256, new BigInteger(1, a).intValue());
}
示例5: encodeImpl
import java.util.BitSet; //导入方法依赖的package包/类
@Override
protected byte[] encodeImpl(Codex<Boolean, E> pData) {
BitSet result = new BitSet(pData.length());
for(int i = 0; i < pData.length(); i++) {
if(pData.get(i)) {
result.set(i);
}
}
return result.toByteArray();
}