Package com.diozero.util
Class BitManipulation
- java.lang.Object
-
- com.diozero.util.BitManipulation
-
public class BitManipulation extends Object
-
-
Constructor Summary
Constructors Constructor Description BitManipulation()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
bytesToWord(int msb, int lsb, boolean isSigned)
static byte
getBitMask(int bitNumber)
static byte
getBitMask(int... bitNumbers)
static boolean
isBitSet(byte value, int bitNumber)
static byte
reverseByte(byte value)
static short
reverseShort(short value)
static byte
setBitValue(byte value, int bitNumber, boolean on)
static byte
updateValueWithMaskedData(byte value, short mask, byte data)
Update only the bits as specified by mask with the specified bits; the value of all other bits are preserved.static byte
updateWithMaskedData(byte value, short mask, byte data, int dataShift)
-
-
-
Method Detail
-
setBitValue
public static byte setBitValue(byte value, int bitNumber, boolean on)
-
getBitMask
public static byte getBitMask(int bitNumber)
-
getBitMask
public static byte getBitMask(int... bitNumbers)
-
isBitSet
public static boolean isBitSet(byte value, int bitNumber)
-
updateWithMaskedData
public static byte updateWithMaskedData(byte value, short mask, byte data, int dataShift)
-
updateValueWithMaskedData
public static byte updateValueWithMaskedData(byte value, short mask, byte data)
Update only the bits as specified by mask with the specified bits; the value of all other bits are preserved. Note: mask is a short to ensure unsigned behaviour.- Parameters:
value
- the value to updatemask
- a bit mask with 1s specifying the bits to updatedata
- the new bits to apply to the value- Returns:
- the updated value
-
bytesToWord
public static int bytesToWord(int msb, int lsb, boolean isSigned)
-
reverseByte
public static byte reverseByte(byte value)
-
reverseShort
public static short reverseShort(short value)
-
-