Class BitArray

  • All Implemented Interfaces:
    Iterable<Boolean>

    @NonNullByDefault
    public class BitArray
    extends Object
    implements Iterable<Boolean>
    Class that implements a collection for bits
    Author:
    Sami Salonen - Initial contribution
    • Constructor Detail

      • BitArray

        public BitArray​(int nbits)
      • BitArray

        public BitArray​(boolean... bits)
      • BitArray

        public BitArray​(BitSet wrapped,
                        int length)
    • Method Detail

      • getBit

        public boolean getBit​(int index)
        Returns the state of the bit at the given index Index 0 matches LSB (rightmost) bit

        Parameters:
        index - the index of the bit to be returned.
        Returns:
        true if the bit at the specified index is set, false otherwise.
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds.
      • setBit

        public void setBit​(int index,
                           boolean value)
      • size

        public int size()
        Get number of bits stored in this instance
        Returns:
      • equals

        public boolean equals​(@Nullable Object obj)
        Overrides:
        equals in class Object
      • toBinaryString

        public String toBinaryString()
        Get data as binary string For example, 0010
        Returns:
        string representing the data