|
@@ -268,13 +268,25 @@ public class ByteUtils {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public static int getBitField(byte b, int field)
|
|
|
- {
|
|
|
- return (b & 1 << field) > 0 ? 1 : 0;
|
|
|
+ public static int getBitField(byte b, int field) {
|
|
|
+ return Math.min(1, b & 255 & 1 << (field % 8));
|
|
|
+// byte setter = (byte)(1 << (field % 8));
|
|
|
+// return (b & setter) > 0 ? 1 : 0;
|
|
|
}
|
|
|
|
|
|
- public static int getBitField(byte b, int field, int count)
|
|
|
- {
|
|
|
+ public static byte setBitField(byte b, int field, int value) {
|
|
|
+ byte result;
|
|
|
+ byte setter = (byte)(1 << (field % 8));
|
|
|
+ if (value == 1) {
|
|
|
+ result = (byte)(b | setter);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ result = (byte)(b & ~setter);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getBitField(byte b, int field, int count) {
|
|
|
if (count == 1) {
|
|
|
count = 1;
|
|
|
} else if (count == 2) {
|
|
@@ -311,14 +323,6 @@ public class ByteUtils {
|
|
|
return b >> field & count;
|
|
|
}
|
|
|
|
|
|
- public static byte setBitField(byte b, int field, int value)
|
|
|
- {
|
|
|
- if ((value == 0) || (value == 1)) {
|
|
|
- b = (byte)(b | value << field);
|
|
|
- }
|
|
|
- return b;
|
|
|
- }
|
|
|
-
|
|
|
public static byte setBitField(byte b, int field, int count, int value)
|
|
|
{
|
|
|
if ((field + count <= 8) && (value < Math.pow(2.0D, count))) {
|