# BitArray

```from panda3d.core import BitArray
```
class BitArray

Bases:

A dynamic array with an unlimited number of bits.

This is similar to a BitMask, except it appears to contain an infinite number of bits. You can use it very much as you would use a BitMask.

Inheritance diagram

__and__(other: BitArray)
__eq__(other: BitArray) bool
__getstate__()
__iand__(other: BitArray)
__ilshift__(shift: int)
__init__()
__init__(param0: BitArray)
__init__(init_value: int)
__init__(from: SparseArray)
__ior__(other: BitArray)
__irshift__(shift: int)
__ixor__(other: BitArray)
__lt__(other: BitArray) bool
__ne__(other: BitArray) bool
__or__(other: BitArray)
__rshift__(shift: int)
__setstate__(state: object)
__xor__(other: BitArray)
static allOff()

Returns a `BitArray` whose bits are all off.

static allOn()

Returns a `BitArray` with an infinite array of bits, all on.

static bit(index: int)

Returns a `BitArray` with only the indicated bit on.

clear()

Sets all the bits in the `BitArray` off.

clearBit(index: int)

Sets the nth bit off. If n >= `getNumBits()`, this automatically extends the array.

clearRange(low_bit: int, size: int)

Sets the indicated range of bits off.

compareTo(other: BitArray) int

Returns a number less than zero if this `BitArray` sorts before the indicated other `BitArray`, greater than zero if it sorts after, or 0 if they are equivalent. This is based on the same ordering defined by operator <.

extract(low_bit: int, size: int) int

Returns a word that represents only the indicated range of bits within this `BitArray`, shifted to the least-significant position. size must be <= `getNumBitsPerWord()`.

getBit(index: int) bool

Returns true if the nth bit is set, false if it is cleared. It is valid for n to increase beyond `getNumBits()`, but the return value `getNumBits()` will always be the same.

static getClassType()
getHighestBits() bool

Returns true if the infinite set of bits beyond `getNumBits()` are all on, or false of they are all off.

getHighestOffBit() int

Returns the index of the highest 0 bit in the array. Returns -1 if there are no 0 bits or if there an infinite number of 1 bits.

getHighestOnBit() int

Returns the index of the highest 1 bit in the array. Returns -1 if there are no 1 bits or if there an infinite number of 1 bits.

getLowestOffBit() int

Returns the index of the lowest 0 bit in the array. Returns -1 if there are no 0 bits.

getLowestOnBit() int

Returns the index of the lowest 1 bit in the array. Returns -1 if there are no 1 bits.

static getMaxNumBits() int
getNextHigherDifferentBit(low_bit: int) int

Returns the index of the next bit in the array, above low_bit, whose value is different that the value of low_bit. Returns low_bit again if all bits higher than low_bit have the same value.

This can be used to quickly iterate through all of the bits in the array.

getNumBits() int

Returns the current number of possibly different bits in this array. There are actually an infinite number of bits, but every bit higher than this bit will have the same value, either 0 or 1 (see `getHighestBits()`).

This number may grow and/or shrink automatically as needed.

static getNumBitsPerWord() int
getNumOffBits() int

Returns the number of bits that are set to 0 in the array. Returns -1 if there are an infinite number of 0 bits.

getNumOnBits() int

Returns the number of bits that are set to 1 in the array. Returns -1 if there are an infinite number of 1 bits.

getNumWords() int

Returns the number of possibly-unique words stored in the array.

Returns the nth word in the array. It is valid for n to be greater than `getNumWords()`, but the return value beyond `getNumWords()` will always be the same.

hasAllOf(low_bit: int, size: int) bool

Returns true if all bits in the indicated range are set, false otherwise.

hasAnyOf(low_bit: int, size: int) bool

Returns true if any bit in the indicated range is set, false otherwise.

hasBitsInCommon(other: BitArray) bool

Returns true if this `BitArray` has any “one” bits in common with the other one, false otherwise.

This is equivalent to (array & other) != 0, but may be faster.

static hasMaxNumBits() bool
invertInPlace()

Inverts all the bits in the `BitArray`. This is equivalent to array = ~array.

isAllOn() bool

Returns true if the entire bitmask is one, false otherwise.

isZero() bool

Returns true if the entire bitmask is zero, false otherwise.

static lowerOn(on_bits: int)

Returns a `BitArray` whose lower on_bits bits are on.

operator(shift: int)
operator(shift: int)
output(out: ostream)

Writes the `BitArray` out as a hex number. For a `BitArray`, this is always the same as `outputHex()`; it’s too confusing for the output format to change back and forth at runtime.

outputBinary(out: ostream, spaces_every: int)

Writes the `BitArray` out as a binary number, with spaces every four bits.

outputHex(out: ostream, spaces_every: int)

Writes the `BitArray` out as a hexadecimal number, with spaces every four digits.

static range(low_bit: int, size: int)

Returns a `BitArray` whose size bits, beginning at low_bit, are on.

setBit(index: int)

Sets the nth bit on. If n >= `getNumBits()`, this automatically extends the array.

setBitTo(index: int, value: bool)

Sets the nth bit either on or off, according to the indicated bool value.

setRange(low_bit: int, size: int)

Sets the indicated range of bits on.

setRangeTo(value: bool, low_bit: int, size: int)

Sets the indicated range of bits to either on or off.

setWord(n: int, value: int)

Replaces the nth word in the array. If n >= `getNumWords()`, this automatically extends the array.

store(value: int, low_bit: int, size: int)

Stores the indicated word into the indicated range of bits with this `BitArray`.

write(out: ostream, indent_level: int)

Writes the `BitArray` out as a binary or a hex number, according to the number of bits.
{"ft_lang_label":"__label__en","ft_lang_prob":0.66644466,"math_prob":0.92988104,"size":4420,"snap":"2022-40-2023-06","text_gpt3_token_len":1126,"char_repetition_ratio":0.16394928,"word_repetition_ratio":0.18691589,"special_character_ratio":0.24276018,"punctuation_ratio":0.1412037,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98913854,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-09-26T05:32:06Z\",\"WARC-Record-ID\":\"<urn:uuid:9e64c985-2bdd-4249-8080-95258da6c8e6>\",\"Content-Length\":\"358190\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f994895c-b66a-4ca1-855a-1b24adfc024b>\",\"WARC-Concurrent-To\":\"<urn:uuid:65093bf7-1089-4805-9b4a-d7ded5808f25>\",\"WARC-IP-Address\":\"128.2.236.121\",\"WARC-Target-URI\":\"https://docs.panda3d.org/1.10/python/reference/panda3d.core.BitArray\",\"WARC-Payload-Digest\":\"sha1:RJ2OGBR4VKW3E77HAQU33F4D6SM5P66A\",\"WARC-Block-Digest\":\"sha1:EARZEKKYZYCJPBP5TG6U6BALZ35RWUTX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030334802.16_warc_CC-MAIN-20220926051040-20220926081040-00099.warc.gz\"}"}