Class Bits
- java.lang.Object
-
- net.emustudio.emulib.runtime.helpers.Bits
-
@NotThreadSafe public class Bits extends java.lang.ObjectBits utility class. Supports various operations on bits.
-
-
Constructor Summary
Constructors Constructor Description Bits(int bits, int length)Constructs new Bits object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Bitsabsolute()Make the absolute value from the number stored in two's complement.BitsreverseBits()Reverses bits in each byte.BitsreverseBytes()Reverses the bytes.BitsshiftLeft()Shift the value to the left.BitsshiftRight()Shift the value to the right.byte[]toBytes()
-
-
-
Method Detail
-
toBytes
public byte[] toBytes()
-
reverseBytes
public Bits reverseBytes()
Reverses the bytes.- Returns:
- this Bits, with bytes reversed
-
reverseBits
public Bits reverseBits()
Reverses bits in each byte.However, order of bytes is kept.
- Returns:
- this Bits, reversed bits within each byte
-
absolute
public Bits absolute()
Make the absolute value from the number stored in two's complement.If the number is already positive, it is kept as-is.
- Returns:
- this Bits - the negative sign is removed
-
shiftLeft
public Bits shiftLeft()
Shift the value to the left.- Returns:
- this Bits with value shifted to the left by 1 bit, padded with zeroes from the right
-
shiftRight
public Bits shiftRight()
Shift the value to the right.- Returns:
- this Bits shifted to the right by 1 bit, padded with zeroes from the left
-
-