Class Bits


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

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

      Constructors 
      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.
        Parameters:
        bits - integer number in little endian
        length - significant bits count
    • 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