📄 bitsetutils.java
字号:
/*================= * Copyright (C) 2001 Todd Kaplan * * Lisys is a program that monitors TCP SYN packets to detect network * traffic anomalies. * * Licensed under the GNU General Public License (GPL), version 2 or * higher. Please see the COPYING and PATENT files included with the * Lisys distribution, which can be found at: * * http://www.cs.unm.edu/~judd/lisys/ * * Also, the current text of the GPL can be found at: * * http://www.gnu.org/copyleft/gpl.html * * Note that Lisys has NO WARRANTY! *=================*/package edu.unm.cs.lisys.util;import edu.unm.cs.lisys.debug.*;import java.util.*;/**========== * BitSetUtils.java * This class adds a couple methods for making BitSets. * * Here are the people who have worked on this code in the order they * have worked on it: * @author Todd Kaplan <kaplan@cs.unm.edu> * @author Justin Balthrop <judd@cs.unm.edu> *==========*/public class BitSetUtils{ /**========== * byteToBitSet: * Makes a BitSet from a byte. * * @param b the byte to be converted * @return a BitSet *==========*/ public static BitSet byteToBitSet(byte b) { BitSet bs = new BitSet(8); int num = (int) b; if (num < 0) num += 256; int divisor = 128; int msb = 7; for (int i = 0; i <= 7; i++) { if ((num / divisor) > 0) { bs.set(i); num -= divisor; } divisor /= 2; } return bs; } /**========== * mergeBytes: * Make a BitSet by merging an array of bytes. * * @param bytes an array of bytes * @return a BitSet *==========*/ public static BitSet mergeBytes(byte[] bytes) { int numBytes = bytes.length; BitSet bs = new BitSet(numBytes); int bits = 8; BitSet tempBS; int index = 0; for (int i = 0; i < numBytes; i++) { tempBS = byteToBitSet(bytes[i]); for (int j = 0; j < bits; j++, index++) { if (tempBS.get(j) == true) bs.set(index); } } return bs; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -