com.google.zxing.common

## Class BitArray

- java.lang.Object
- - com.google.zxing.common.BitArray

- All Implemented Interfaces:
    Cloneable

      public final class BitArray
      extends Object
      implements Cloneable

  A simple, fast array of bits, represented compactly by an array of ints internally.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BitArray()` Creates a new empty BitArray with zero size.
    `BitArray(int size)` Creates a new BitArray with the specified size.
    `BitArray(int[] bits, int size)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `appendBit(boolean bit)` Appends a single bit to the end of the array.
    `void` | `appendBitArray(BitArray other)` Appends another BitArray to the end of this array.
    `void` | `appendBits(int value, int numBits)` Appends the least-significant bits, from value, in order from most-significant to least-significant.
    `void` | `clear()` Clears all bits (sets to false).
    `BitArray` | `clone()`
    `boolean` | `equals(Object o)`
    `void` | `flip(int i)` Flips bit i.
    `boolean` | `get(int i)`
    `int[]` | `getBitArray()`
    `int` | `getNextSet(int from)`
    `int` | `getNextUnset(int from)`
    `int` | `getSize()`
    `int` | `getSizeInBytes()`
    `int` | `hashCode()`
    `boolean` | `isRange(int start, int end, boolean value)` Efficient method to check if a range of bits is set, or not set.
    `void` | `reverse()` Reverses all bits in the array.
    `void` | `set(int i)` Sets bit i.
    `void` | `setBulk(int i, int newBits)` Sets a block of 32 bits, starting at bit i.
    `void` | `setRange(int start, int end)` Sets a range of bits.
    `void` | `toBytes(int bitOffset, byte[] array, int offset, int numBytes)`
    `String` | `toString()`
    `void` | `xor(BitArray other)` Performs a bitwise XOR of this array with another.

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### BitArray

          public BitArray()

      Creates a new empty BitArray with zero size.

    - #### BitArray

          public BitArray(int size)

      Creates a new BitArray with the specified size.
      Parameters:
        `size` - the number of bits in the array

    - #### BitArray

          BitArray(int[] bits,
                   int size)

  - ### Method Detail

    - #### appendBit

          public void appendBit(boolean bit)

      Appends a single bit to the end of the array.
      Parameters:
        `bit` - the bit value to append

    - #### appendBitArray

          public void appendBitArray(BitArray other)

      Appends another BitArray to the end of this array.
      Parameters:
        `other` - the BitArray to append

    - #### appendBits

          public void appendBits(int value,
                                 int numBits)

      Appends the least-significant bits, from value, in order from most-significant to least-significant. For example, appending 6 bits from 0x000001E will append the bits 0, 1, 1, 1, 1, 0 in that order.
      Parameters:
        `value` - `int` containing bits to append
        `numBits` - bits from value to append

    - #### clear

          public void clear()

      Clears all bits (sets to false).

    - #### clone

          public BitArray clone()

      Overrides:
        `clone` in class `Object`
      Returns:
        a copy of this BitArray

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`
      Parameters:
        `o` - the object to compare
      Returns:
        true if this BitArray equals the given object

    - #### flip

          public void flip(int i)

      Flips bit i.
      Parameters:
        `i` - bit to set

    - #### get

          public boolean get(int i)

      Parameters:
        `i` - bit to get
      Returns:
        true iff bit i is set

    - #### getBitArray

          public int[] getBitArray()

      Returns:
        underlying array of ints. The first element holds the first 32 bits, and the least significant bit is bit 0.

    - #### getNextSet

          public int getNextSet(int from)

      Parameters:
        `from` - first bit to check
      Returns:
        index of first bit that is set, starting from the given index, or size if none are set at or beyond this given index
      See Also:
        `getNextUnset(int)`

    - #### getNextUnset

          public int getNextUnset(int from)

      Parameters:
        `from` - index to start looking for unset bit
      Returns:
        index of next unset bit, or `size` if none are unset until the end
      See Also:
        `getNextSet(int)`

    - #### getSize

          public int getSize()

      Returns:
        the number of bits in the array

    - #### getSizeInBytes

          public int getSizeInBytes()

      Returns:
        the size of the array in bytes (rounded up)

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`
      Returns:
        the hash code value for this BitArray

    - #### isRange

          public boolean isRange(int start,
                                 int end,
                                 boolean value)

      Efficient method to check if a range of bits is set, or not set.
      Parameters:
        `start` - start of range, inclusive.
        `end` - end of range, exclusive
        `value` - if true, checks that bits in range are set, otherwise checks that they are not set
      Returns:
        true iff all bits are set or not set in range, according to value argument
      Throws:
        `IllegalArgumentException` - if end is less than start or the range is not contained in the array

    - #### reverse

          public void reverse()

      Reverses all bits in the array.

    - #### set

          public void set(int i)

      Sets bit i.
      Parameters:
        `i` - bit to set

    - #### setBulk

          public void setBulk(int i,
                              int newBits)

      Sets a block of 32 bits, starting at bit i.
      Parameters:
        `i` - first bit to set
        `newBits` - the new value of the next 32 bits. Note again that the least-significant bit corresponds to bit i, the next-least-significant to i+1, and so on.

    - #### setRange

          public void setRange(int start,
                               int end)

      Sets a range of bits.
      Parameters:
        `start` - start of range, inclusive.
        `end` - end of range, exclusive

    - #### toBytes

          public void toBytes(int bitOffset,
                              byte[] array,
                              int offset,
                              int numBytes)

      Parameters:
        `bitOffset` - first bit to start writing
        `array` - array to write into. Bytes are written most-significant byte first. This is the opposite of the internal representation, which is exposed by `getBitArray()`
        `offset` - position in array to start writing
        `numBytes` - how many bytes to write

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`
      Returns:
        a string representation of this BitArray

    - #### xor

          public void xor(BitArray other)

      Performs a bitwise XOR of this array with another.
      Parameters:
        `other` - the BitArray to XOR with
      Throws:
        `IllegalArgumentException` - if sizes don't match