Class Bits

  • @NotThreadSafe
    public class Bits
    extends java.lang.Object
    Bits utility class. Supports various operations on bits.
    • Field Summary

      Modifier and Type Field Description
      int bits  
      int length  
    • Constructor Summary

      Constructor Description
      Bits​(int bits, int length)
      Constructs new Bits object.
    • Field Detail

      • bits

        public int bits
      • length

        public final int length
    • Constructor Detail

      • Bits

        public Bits​(int bits,
                    int length)
        Constructs new Bits object.
        bits - integer number in little endian
        length - significant bits count
    • Method Detail

      • toBytes

        public byte[] toBytes()
      • reverseBytes

        public Bits reverseBytes()
        Reverses the bytes.
        this Bits, with bytes reversed
      • reverseBits

        public Bits reverseBits()
        Reverses bits in each byte.

        However, order of bytes is kept.

        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.

        this Bits - the negative sign is removed
      • shiftLeft

        public Bits shiftLeft()
        Shift the value to the left.
        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.
        this Bits shifted to the right by 1 bit, padded with zeroes from the left