/**
* byte[]工具类
*/
public class byteUtils {
public int getBit(byte b, int i) {
return ((b >> i) & 0x1);
}
//b为传入的字节,start是起始位,length是长度,如要获取bit0-bit4的值,则start为0,length为5
public int getBits(byte b, int start, int length) {
return ((b >> start) & (0xFF >> (8 - length)));
}
public byte setBit(int position, int value) {
return (byte) (value << position);
}
public byte setBit(byte b, int position, int value) {
return (byte) (b | ((byte) value << position));
}
}