Package com.google.zxing.common
Class BitArray
java.lang.Object
com.google.zxing.common.BitArray
- All Implemented Interfaces:
- Cloneable
A simple, fast array of bits, represented compactly by an array of ints internally.
- Author:
- Sean Owen
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidappendBit(boolean bit) voidappendBitArray(BitArray other) voidappendBits(int value, int numBits) Appends the least-significant bits, from value, in order from most-significant to least-significant.voidclear()Clears all bits (sets to false).clone()booleanvoidflip(int i) Flips bit i.booleanget(int i) int[]intgetNextSet(int from) intgetNextUnset(int from) intgetSize()intinthashCode()booleanisRange(int start, int end, boolean value) Efficient method to check if a range of bits is set, or not set.voidreverse()Reverses all bits in the array.voidset(int i) Sets bit i.voidsetBulk(int i, int newBits) Sets a block of 32 bits, starting at bit i.voidsetRange(int start, int end) Sets a range of bits.voidtoBytes(int bitOffset, byte[] array, int offset, int numBytes) toString()void
- 
Constructor Details- 
BitArraypublic BitArray()
- 
BitArraypublic BitArray(int size) 
 
- 
- 
Method Details- 
getSizepublic int getSize()
- 
getSizeInBytespublic int getSizeInBytes()
- 
getpublic boolean get(int i) - Parameters:
- i- bit to get
- Returns:
- true iff bit i is set
 
- 
setpublic void set(int i) Sets bit i.- Parameters:
- i- bit to set
 
- 
flippublic void flip(int i) Flips bit i.- Parameters:
- i- bit to set
 
- 
getNextSetpublic 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:
 
- 
getNextUnsetpublic int getNextUnset(int from) - Parameters:
- from- index to start looking for unset bit
- Returns:
- index of next unset bit, or sizeif none are unset until the end
- See Also:
 
- 
setBulkpublic 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.
 
- 
setRangepublic void setRange(int start, int end) Sets a range of bits.- Parameters:
- start- start of range, inclusive.
- end- end of range, exclusive
 
- 
clearpublic void clear()Clears all bits (sets to false).
- 
isRangepublic 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
 
- 
appendBitpublic void appendBit(boolean bit) 
- 
appendBitspublic 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-- intcontaining bits to append
- numBits- bits from value to append
 
- 
appendBitArray
- 
xor
- 
toBytespublic 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
 
- 
getBitArraypublic int[] getBitArray()- Returns:
- underlying array of ints. The first element holds the first 32 bits, and the least significant bit is bit 0.
 
- 
reversepublic void reverse()Reverses all bits in the array.
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
- 
clone
 
-