| 1 | package com.rox; | |
| 2 | ||
| 3 | public final class ByteUtil { | |
| 4 | /** Mask to remove any digits that don't represent a byte, i.e. the 8 least significant bits */ | |
| 5 | public static final int BYTE_MASK = 0xFF; | |
| 6 | /** Mask to remove any digits that don't represent a word, i.e. the 16 least significant bits */ | |
| 7 | public static final int WORD_MASK = 0xFFFF; | |
| 8 | ||
| 9 | public static final int[] bitMap = new int[] { | |
| 10 | 0b0000000000000001, //Byte | |
| 11 | 0b0000000000000010, | |
| 12 | 0b0000000000000100, | |
| 13 | 0b0000000000001000, | |
| 14 | 0b0000000000010000, | |
| 15 | 0b0000000000100000, | |
| 16 | 0b0000000001000000, | |
| 17 | 0b0000000010000000, | |
| 18 | 0b0000000100000000, //Word | |
| 19 | 0b0000001000000000, | |
| 20 | 0b0000010000000000, | |
| 21 | 0b0000100000000000, | |
| 22 | 0b0001000000000000, | |
| 23 | 0b0010000000000000, | |
| 24 | 0b0100000000000000, | |
| 25 | 0b1000000000000000 | |
| 26 | }; | |
| 27 | ||
| 28 | private ByteUtil(){ | |
| 29 | } | |
| 30 | ||
| 31 | public static boolean isBitSet(final int bitIndex, final int value) { | |
| 32 |
3
1. isBitSet : negated conditional → KILLED 2. isBitSet : Replaced bitwise AND with OR → KILLED 3. isBitSet : replaced boolean return with true for com/rox/ByteUtil::isBitSet → KILLED |
return (bitMap[bitIndex] & value) != 0; |
| 33 | } | |
| 34 | ||
| 35 | public static int withBitSet(final int value, final int bitIndex) { | |
| 36 |
2
1. withBitSet : replaced int return with 0 for com/rox/ByteUtil::withBitSet → KILLED 2. withBitSet : Replaced bitwise OR with AND → KILLED |
return value | bitMap[bitIndex]; |
| 37 | } | |
| 38 | ||
| 39 | /** Each byte as {@code 0-255}, e.g. {@code (byte) 0xFF} becomes {@code 255}, not {@code -1}. */ | |
| 40 | public static int[] toUnsigned(final byte[] bytes){ | |
| 41 | final int[] values = new int[bytes.length]; | |
| 42 |
2
1. toUnsigned : negated conditional → KILLED 2. toUnsigned : changed conditional boundary → KILLED |
for (int i = 0; i < bytes.length; i++){ |
| 43 |
1
1. toUnsigned : Replaced bitwise AND with OR → KILLED |
values[i] = bytes[i] & BYTE_MASK; |
| 44 | } | |
| 45 |
1
1. toUnsigned : replaced return value with null for com/rox/ByteUtil::toUnsigned → KILLED |
return values; |
| 46 | } | |
| 47 | ||
| 48 | /** The low 8 bits of each value. */ | |
| 49 | public static byte[] toBytes(final int[] values){ | |
| 50 | final byte[] bytes = new byte[values.length]; | |
| 51 |
2
1. toBytes : changed conditional boundary → KILLED 2. toBytes : negated conditional → KILLED |
for (int i = 0; i < values.length; i++){ |
| 52 | bytes[i] = (byte) values[i]; | |
| 53 | } | |
| 54 |
1
1. toBytes : replaced return value with null for com/rox/ByteUtil::toBytes → KILLED |
return bytes; |
| 55 | } | |
| 56 | } | |
Mutations | ||
| 32 |
1.1 2.2 3.3 |
|
| 36 |
1.1 2.2 |
|
| 42 |
1.1 2.2 |
|
| 43 |
1.1 |
|
| 45 |
1.1 |
|
| 51 |
1.1 2.2 |
|
| 54 |
1.1 |